从另一个视图中选择 tableview 的行 [英] select tableview's row from an another view
本文介绍了从另一个视图中选择 tableview 的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我制作了一个 TabViewController
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??
谢谢..
推荐答案
如果您有第二个视图的参考 - 使用 @Praveen 的回答.
If you have a refernce to the second view - use answer by @Praveen.
如果没有,您可以使用通知,如下所示:
If not, you can use Notifications, like this:
在视图A"中:
[[NSNotificationCenter defaultCenter] postNotificationName:@"selectRow" object:[NSNumber numberWithInt:rowNumber]]];
在视图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];
}
这篇关于从另一个视图中选择 tableview 的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文