Handling buttons within UITableViewCells - iphone

I have a UITableView loading cells from a nib. On each table view cell, there are two buttons. When the button is tapped, I need to update other fields in the view that contains the table view.
In the past I've used a delegate on the table view cell to call back to the view controller to tell it that which button was tapped and used tags on the cell to find the cell's index. The problem I'm currently facing is that this sort of behavior happens in multiple places throughout my application and delegate patterns everywhere could get messy quick.
Is there a better method to message the tableview's parent view controller when a button on a specific cell has been tapped? I need to know which cell was tapped and which button on the cell was tapped.

Yeah, the better method is to make your controller the target of the button's action method. You'll still need to use tags to get the index path of the cell the button was in. You can hook up the action method in IB, or in cellForRowAtIndexPath.

Related

Swift//How can I add an action to a button inside a custom view class, where the action need to access a tableView Cell property?

I made a custom UIView class, it has a viwe and inside that view there is a button. The problem is implement the action for the button, the action that i need is when press that button a label textcolor inside a table view cell should changed to another color. How I can make that action work.
I tried to make a delegate and set it inside the tableview controller but is did not work :(

Call segue on tap of UITextView swift?

I have a UITextView embedded in each cell of my UITableView. Clicking the cell calls another view controller but clicking the textview inside the cell doesn't (but I want it to). How can I fix this?
Uncheck User Interaction Enabled in the storyboard under the View category of the Attributes Inspector for your UITextView.

Segue not performing

I'm currently facing something I find rather strange.
In my storyboard, there is a TableViewController filled with static cells.
I would like to perform a simple segue (a push to another view controller) when I select one of the rows.
So I "ControlDrag" from the concerned table cell to the sibling controller, but when tap one the cell, nothing happens. Next to that, I did try assigning the segue triggering to the accessory view of the cell (a disclosure button). And in that case, the segue is effectively triggered.
So here is my question : Should I use the "programmatic way" to handle the tap on the cell (tableview delegate methods and manual segue performing), or is there something I'm missing in the interface builder? And btw how could we explain the behavior difference with the accessory button view ?
Here is two screenshot
Cell selection that should trigger segue
And, the accessory action which performs the segue
I finally found what the problem was. I had a gesture recognizer attached to the view controller, and it was catching the tap event on the cell.

trying to create a login view with grouped tableview

Trying to create a login screen like the one in the facebook app. Trying to do it with a grouped tableview with a button underneath. If I choose static cells I must enclose it in a tableview controller, but I don't want it to a table view controller since I want to put in other elements in the view. If I set it to Dynamic prototype the don't show up at all.
I'm doing this in the Storyboard interface.
Right now it looks like this in Storyboard:
ViewController
View
TableView
Table View Cell
Table View Cell
Button
Thanks.

can't update text fields in a UIViewController that pushed onto a UINavigation Controller

I have a UINavigationController that gets UIViewControllers pushed onto it. In the first view there is a grouped table view which has 3 rows, each containing a UITextField with initial text set on viewWillLoad of that view controller. Tapping any one of the table view cells pushes the 2nd UIViewController onto the nav controller's stack. Each of the secondary view controllers has another table view where the user can select a choice by touching one of the rows.
The experience is identical to the iPhone's ical, when selecting "repeat" for an event.
The problem is that when the user touches the UIBarButtonItem to save, and I set the selected value into the previous views text field, the text field doesn't update. Regardles of what text I set it doesn't update when the navigation controller pops back to the first view. Could it be cached, or the view cached as a whole?
I'm logging all the values and everything looks correct.
Sorry to not post any code, I'm not sure how to without posting a book.
You could do a reloadData when the main view reappears. This forces the table to refetch the visible rows and redraw them.
[theTable reloadData];
Edit: an improvement would be to only reload the row affected, instead of reloading all the visible rows with the reloadRowsAtIndexPaths:withRowAnimation: method.