select tableview's row from an another view

久未见 提交于 2019-12-08 02:07:59

问题


I have made a TabViewController

In that there is a view with a table and a view with an Image and some buttons.

Now I want that when I press button one of the view one the row one from the another view should be selected. and when I press button two...row two from the another view should be selected ..

can anyone tell me logically or with coding how to do this??

Thanks..


回答1:


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];
}



回答2:


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.



来源:https://stackoverflow.com/questions/5324501/select-tableviews-row-from-an-another-view

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