Button changes cell detail label - ios

Setup: i have a view controller with a tableview inside it. I also have a button in the view controller. What I want to do is when I click the button, it should change the detail label text. What i having going now is my button action, and then my cellForRowAtIndexPath. Essentially i need to tell me cell that when my button is click to change the detail text with whatever information i want. I'm stuck with this...I can assign the button to change any label...but i can't figure out how to change the detail label with the button click. Any help would be great.

You typically set the content of a uitableviewcell (which includes textLabel.text and detailTextLabel.text) in cellForRowAtIndexPath method using a datasource. This datasource could be any model object derived by NSObject or it could be NSDictionary. When you process the button tap in button's action method, just update your datasource object for the row/section with the desired detailTextLabel text and call [tableView reloadData] to reload your tableview.

Related

How to recognize gesture from custom view in VC

I have tableVC, it contains from cells with customViews.
That customViews contains from 3 imageViews, so then I click on imageView, it makes some action. To achieve it I added UITapGestureRecognizers to imageView.
Now I need to be notified then this cells are tapped in my tableVC. I get this events in didSelectRowAtIndexPath, but only if I do not touch any of imageViews with gestures.
How can I receive tap notification in my tableVC about touching my cell completely ?
If you want to get cell that is tapped - didSelectRowAtIndexPath is way to go. If you want to get the tapped image inside that cell - implement delegate for that ( https://developer.apple.com/library/ios/documentation/General/Conceptual/CocoaEncyclopedia/DelegatesandDataSources/DelegatesandDataSources.html ) and do the corresponding actions. I see that you mentioned didSelectRowAtIndexPath, but I am not sure what was your problem.
Also I didn't put any code since I don't know if you are using swift or objective-c.

calling reloadItemsAtIndexPaths not using dequeueReusableCellWithReuseIdentifier

When I create a collection view with a custom cell (the collection view has 10 elements) by using dequeueReusableCellWithReuseIdentifier and then call reloadItemsAtIndexPaths to upload cell on button click, I get null for properties which were set to CustomCollectionViewCell inside the cellForItemAtIndexPath method.
I tried debugging and I found that the initWithFrame method of the custom cell is called the first time the app is run, and then a second time when the button is clicked for the first time.
Each time I press the button (after the first button press), the method initWithFrame of the custom cell is not called.
Can someone help me?
I want those properties to be stored, and not reset the first time the button is pressed.

iOS picker view as default input method

I have labelA in my custom tableview cell. When I click on the label I want picker view to be shown in the bottom of the screen in order to choose available options.
My question is: Do I actually need drag and drop PickerView into my view in storyboard or I can just invoke it as default input method? (Same as keyboard for text field)
If yes, how do I do that? - All I want when label is clicked show picker and hide it on when selection is finished. Could you please provide me some examples?
I am developing under swift but iOS example is fine as well.
Thanks for any help!
Edit:
Well label is not principle, I can use just input trigger from the cell directly. Idea after click show picker view and hide it after selection.
What I mostly do is use a UITextField and set the inputAccessoryView property to an instance of UIPickerView. This will display the UIPickerView once you tap on the UITextField instead of the default keyboard.
You can instantiate the UIPickerView all in code in your tableView:didSelectRowAtIndexPath method. You can either add it to your view controller using self.view addSubView. You will have to write code to place it properly on the screen with your table view. You might want to resize your table view so it shrinks and your picker view is shown on the bottom of your view.
An easier way could be to show a modal dialog with your UIPickerView already set up.
UPDATE
Create an new controller that is of type UIViewController.
Drag a UIViewController onto your storyboard and give it the type of the above controller and a storyboard id. I use the name of the UIViewController created.
Add your picker view to that and configure your data source.
Create a delegate for the option selected and have it return the item selected.
- (void)selectionMade:(NSString *)selectedValue;
In your table view controller, implement that delegate method above.
In tableView:didSelectRowAtIndexPath, load that view controller and show it.
[self.storyboard instantiateViewControllerWithIdentifier:#""]
Your delegate method will get that value and you can retrieve the cell using tableView.indexPathForSelectedRow.
Update you cell accordingly.

iOS UITableView: didSelectRowAtIndexPath not reacting for clicks everywhere

I have several UITableViews which should segue further in my navigation controller. First I've created the segues directly from the table view cells. But then I've noticed that in the smaller cells if you click on the label or somewhere, this method didSelectRowAtIndexPath doesn't get triggered. Only if you click on an "empty" space in the cell.
So I've created the segue for the whole view and just called performSegueWithIdentifier in the didSelectRowAtIndexPath method.
But still the same problem. Is this only my impression that you have to click on empty parts or onto the right side of a cell to perform a segue or is something else wrong? Or how could I make the whole cell reactive?
You might try turning off User interaction enabled for the labels in your cell.

Push Detail View from UITableView only on a specific UIImage in the cell?

I've got a UITableView which pushes a detail view when I tap any of its cells. I'd like that segue to only occur when tapping a specific part of the cell, a UIImageView at its left side. Tapping the rest of the cell should trigger a UITapGestureRecognizer which triggers a different method.
How can I override the default tap on the UITableViewCell, so that simply tapping anywhere on the cell doesn't trigger the segue to the detail view? I still want that transition, just only triggered by the UIImageView.
I think you could achieve that by connecting the segue with the image in the prototype cell (Never tried that myself) and not with the table view.
If you don't have a prototype cell then you should programmatically invoke an IBAction type of method with the image views. Well, Image Views cannot do that. Simply abuse a UIButton of the same size, custom style and assign the image to that button. Works fine.
(It does not need to be an -(IBAction) type of method, but it does not harm and doing so ensures that everything works fine.)
Within that action method invoke the segue programmatically. The segue needs to have an ID for that which is unique within the storyboard.

Resources