Search code examples
iphoneuitableviewuiviewcontrollerxcode4.2didselectrowatindexpath

Calling same view Controller but need different actions


i have a view controller with a list of categories which is in an UITableView.I push this View Controller in three other viewcontrollers.so the same functionality of the tableView is getting applied when ever it is called which i dont want to happen.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{ 
self.index = indexPath;
[retrieveName getItemName:[self.arrayForCategories objectAtIndex:indexPath.row]];
[self dismissModalViewControllerAnimated:YES];
[tableView reloadData];
}

This method should work only when it is called from one view controller.any idea??


Solution

  • You could subclass the view controller, and include that method in the subclass. Then you just use the subclass for the view controller that you want that functionality in.

    Or, you could have a BOOL property that determines whether or not the table view should respond to selections, and set that property before pushing the view controller (set it in prepareForSegue:sender: if you are using storyboards).