I have a UIViewController which contains a UITableView (amongst other views).
The UITableView could get its cells from one of two UITableDataSource, depending on some condition.
My UITableDataSource class also acts as my UITableViewDelegate.
When a cell is selected (tableView:didSelectRowAtIndexPath) I may want to perform an action on the UIViewController, such as performSegue or show an alert.
What would be the best way to do this?
- Add a weak reference to the
UIViewControllerinside each datasource/delegate class - Create a delegate per datasource/delegate class which calls functions inside my
UIViewController - Your suggestion here!
I considered making my UIViewController the UITableViewDelegate but as the cells are different depending on the source I thought it would get messy.
Note: I say "best way" but really I am just interested in alternate approaches
The most common approach is to subclass UITableViewController and implement
UITableViewDelegateandUITableDataSourcethere. You can return whichever cell you require incellForRowAtIndexPathbased on any state in your controller class.