开发者

select tableview's row from an another view

开发者 https://www.devze.com 2023-02-17 16:39 出处:网络
I ha开发者_JAVA百科ve made a TabViewController In that there is a view with a table and a view with an Image and some buttons.

I ha开发者_JAVA百科ve 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..


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消