Swift - Stepper in TableViewCell - Action not Responding - ios

Another Swift beginner here. I have a Stepper in a TableView cell which needs to update a label in the same cell. I got part of the way there by asking another question and I received a great answer here: https://stackoverflow.com/a/42877313/3692615.
I think I understand how the code is supposed to work, and my label is updating with the initial value, but unfortunately the stepper action doesn't seem to be connected properly.
I have tried:
Making sure I do not have redundant outlets in the connections inspector
Clean/Build project
Delete all outlets completely and reconnect
Tried changing the sender on the stepper action from UIStepper to AnyObject
I'm running out of ideas. Here is a screenshot of the connections inspector.
Here is the logic. Its basically a model class at the top. Then the outlets along with a property 'buyStat' to hold the current data source item and to update the stepper and label when buyStat is set. That's all working, but the stepper action below it is not. I can't get "stepper working" to print.
Then if it helps, here is my ViewController class
If anyone notices anything or has another idea for me to troubleshoot it would be appreciated. Thanks.

You've disabled the user interaction in your cell for row at index method:
cell.isUserInteractionEnabled = false;
You should remove this line.

Related

Passing data from a normal label in one viewconroller to a label inside a collectionView in another viewcontroller?

So, I have a viewController, updatingIdentifiers, with a few textfields - all of which have a connected button, which puts the text from the textfield into a label (all in the same viewcontroller).
When you click to "Open this diary" and proceed to the next viewcontroller, you enter a UICollectionViewController, yourDiary.
Each cell that the user creates in here, holds a couple of edible labels/textfield - but also holds a few labels, that should always have the text from the labels in the previous viewController, updatingIdentifiers.
So how do I set the labels in the UICollectionViewCells to have the data from the previous viewController's labels?
I tried storing the data from the labels in a seperate class, DiaryIdentifiers (NSObject), but I still couldn't find out how to access this data in the UICollectionViewController's code?
I'm pretty new in programming - and also don't if I should enter my code or a screenshots of my code here or if this will just be confusing?
Please let me know if pieces of the code will make it easier to help me! :)
Thanks a lot!
Anton

Two way binding for UIButton in Swift

I'm new to RXSwift. I have UITableViewCell, which has a button. I need to change button state once I click on select all button which is outside of the tableview. I'm changing view model value but UI is not getting updated. Following way I'm binding, how to bind it two ways?
var isSelectedAttendee: Variable<Bool>
cellViewModel?.isSelectedAttendee.asObservable().bind(to: selectButton.rx.isSelected).disposed(by: disposeBag)
Its not duplicated, simple button binding I know but in my case button is inside UITableViewCell. I have tried with different solutions but it didnt solve my problem.
Have a read of this it is, the author has already answered this
https://github.com/ReactiveX/RxSwift/issues/606

UICollectionview with IBOutlet-UIButtons not working

I have a two-days-brain-breaking-question to all of you:
I integrated a menu in my application by using a UICollectionView (one line, horizontal scrolling, fixed number of 9 items). Every cell has an own tag and uses an own prototype cell with own identifier. During the cellForItemAtIndexPath I assign a prototype cell to every cell (the prototype cell contains the specific UIButton in the storyboard). If you click a cell (respective the UIButton) a popover should open (this is working quite well, because the popover is anchored to the collection view not to the cell - otherwise Xcode will give an error, because of an outlet bind to repeating content.). Now to the questions:
Dependently from the chosen value in the popover, the name (titleLable.text) of the button should change. I think, an IBOutlet is needed, but not usable, because of the possible (but not happened) multiple (re)use of the cell.
Some other action in the APP could happened randomly, that changes the label of the button. Therefore an IBOutlet is needed too, I think.
I tried to give the prototypes a specific tag, but this (in my opinion) could not be used, because I cannot assign the tags to an UIButton, during loading, because not all of the cells are visible and therefore not reachable in viedDidAppear...
Any help is appreciated. This is a new try for an old problem and the collectionView till yesterday looked quite promising. Any ideas to help? Thanks a lot. I canĀ“t give code, because 90% of the work are done in IB.
you can use NSNotificationCenter to send message from your UIPopoverController to a UICollectionViewCell.
Send and receive messages through NSNotificationCenter in Objective-C?
Just subclass UICollectionViewCell to MyCollectionViewCell and use your subclass in your UICollectionView.
At the -(void)initWithFrame:(CGRect)frame method of MyCollectionViewCell you should subscribe as an observer to NSNotificationCenter, and unsubscribe in dealloc.
Than all your cells may receive notification and react to it.
This is not an optimal way of receiving callbacks, but maybe the simplest.

How do I get an event message from UITextField in a custom table cell to the table cell?

I'm sure this is a very noddy question, but I just can't get anything useful from the manuals.
I've a UITextField embedded in a custom UITableViewCell. If I use a delegate for the UITextView - it just gives me the UITextView.
If I link the event to the ParerentViewController, it just gives me the ID of the UITextView.
What I want to do is handle the event at the UITableViewCell level. Can I get the events from this text control to feed to the parent, and handle them at the parent level.
I don't seem to even be able to find the parent cell from the UITextField that the handler gives me. How do I find out which cell within the table the UITextField is in when I'm trying to process the events.
I have to be missing something obvious, as I've done this in earlier (pre storyboard) versions, and I'm sure it wasn't this difficult.
Answered a similar question the other day. See the accepted answer.
How can I get index path of cell on switch change event in section based table view
This will let you handle the text changes in the cell and pass them on to the table view. In your case its a UITextView and not a UISwitch.
Add properties to the cell for anything you will need inside the block code when it is called.
Create a subclass of UITableViewCell and implement the textField delegates inside the subclass. The code is lengthy but if you want I can post it when I get time.

reloadData() and setting IBOutlets without Interface Builder

I have created a UITableView inside my UIViewController programmatically using this guide on the Speak Objectively Blog.
However I now have the problem that .reloadData() isn't refreshing the view. However if I drag or move inside the UITableView the data appears correctly.
This answer suggests that I haven't set up the outlet. To my understanding IBOutlets are for connecting elements in the Interface Builder to the code. Please correct me if my understanding here is wrong.
How do I set an outlet if I created the UITableView programmatically?
The guide creates a UITableViewController. It has already an instance of UITableView on it, and it is the one you see in screen. There's no need of creating outlets, so that answer is not actually the answer to your problem (but might be somehow related)
What I can imagine is that you are sending the message somewhere else.
As you can see in the Table View Controller Class Reference , you can get your table view by self.tableView (or just tableView in swift)
So make sure you are sending the message to self.tableView.reloadData()
If it doesn't work, sending part of your code will help us to see better than to imagine where could be the problem ;)
If self.tableView.reloadData() doesn't work on its own, use:
dispatch_async(dispatch_get_main_queue(), {self.tableView.reloadData()})
or
dispatch_async(dispatch_get_main_queue()) {self.tableView.reloadData()}

Resources