select tableview's row from an another view

末鹿安然 提交于 2019-12-06 14:21:41

If you have a refernce to the second view - use answer by @Praveen.

If not, you can use Notifications, like this:

In View 'A':

   [[NSNotificationCenter defaultCenter] postNotificationName:@"selectRow" object:[NSNumber numberWithInt:rowNumber]]];

In View 'B':

[[NSNotificationCenter defaultCenter] addObserver:self                                           selector:@selector(selectRow:) name:@"selectRow" object:nil];

- (void) selectRow:(NSNotification*)n {
   NSNumber* row = [n object];
   NSIndexPath * indexPath = [NSIndexPath indexPathForRow:[row intValue] inSection:0];
   [itemsTableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionBottom];
}

Do you have reference to two views?

Direct method call using the views instance.

- (IBAction) view1ButtonPressed:(id)view1Button
{
  [view2 buttonPressedWithData]; // You can pass some data to view 2
}

There are other methods to do it also, basically if you have the reference to any object you can pass messages to it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!