I have a UItableViewController with a custom cell designed using interface builder. The custom cell has a button and a label on it. The button when click will trigger an alert view with prompt. Once the text is entered and press OK the label on the cell will display the updated info on the table. The problem is the label will not get updated until I click on one of the cells. I cannot use [tableview reloaddata] because I am using IB and it creates a separate .h and .m UItableViewCell files and this is where I put the alert view with prompt code in it. How can I call reload data to update the table when the alert view is dismissed. I have put [tableview reloaddata] in the UItableViewController under viewWillAppear, but it does not work.
views:
802answers:
3You could keep reference to UITableViewController and call reloaddata on it from cell.
I am fairly new to iPhone development, however, one of the design patterns I have seen again and again is delegation. This allows you to extend functionality while maintaining reusability of your components.
I believe you can set a delegate for a UIAlertView and then implement the protocol on your main UITableViewController via in the @interface definition. This means that your controller will be notified of events as they pertain to that particular alert as long as you set the delegate property in your AlertView object after instantiation.
Take a look at the function...
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
If you set up the above delegation, then overload this function, you should be able to call [tableview reloadData] when the alert view is specifically pressed.
Also -- is there a reason you can't define the IBAction method that the button calls in the UITableViewController? This would allow you to avoid passing around the parent of the cell, seems like a better adherence to MVC.