【发布时间】:2016-03-18 18:42:59
【问题描述】:
我处于需要从另一个调用中调用 didSelectRowAtIndexPath 的情况,因为我确实喜欢这样 我创建该类的对象并调用 viewdidload 以便我的表视图被初始化
- (void)_hideTapped:(id)sender
{
LeftController *left = [[LeftController alloc]init];
[left viewDidLoad ];
}
在左控制器中
- (void)viewDidLoad {
[super viewDidLoad];
mainArray = [[NSMutableArray alloc]initWithObjects:@"Go To Camera",@"Big Contacts List",@"Where Am I? On map",@"Watch And Alarm",@"Calculator With Big Letters",@"Big KeyBoard For Email",@"Calendar With Events",@"Settings", nil ];
// NSLog(@"mainArray%@",mainArray);
if (!_tableView) {
UITableView *tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
tableView.delegate = (id<UITableViewDelegate>)self;
tableView.dataSource = (id<UITableViewDataSource>)self;
[self.view addSubview:tableView];
self.tableView = tableView;
[self iDecideWhichCell];
}
}
-(void)iDecideWhichCell
{
NSIndexPath *path = [NSIndexPath indexPathForRow:0 inSection:0];
[self tableView:self.tableView didSelectRowAtIndexPath:path];
}
这是我的 didSelectRowAtIndexPath 的一部分 我正在将 JASidePanels 用于像 facebook 这样的 splitview,这就是他们如何推动 viewcontroller
if (indexPath.row ==0)
{
NSLog(@"%@",tableView);
self.sidePanelController.centerPanel = [[UINavigationController alloc] initWithRootViewController:[[NewViewController alloc] init]];
}
请任何人告诉我如何实现这一目标 我检查了这个答案calling didSelectRowAtIndexPath from other ViewController not responding iPad
但我不明白如何在我的代码中实现这一点
【问题讨论】:
-
为该类提供委托和数据源,例如 tableView.delegate = youClassName;和 tableView.datasource = youClassName;
-
这是一个委托方法 - 不要直接调用它。致电
[object_holding_tableView.tableView selectRowAtIndexPath:...animated:NO];您将需要对包含您的表格视图的对象的引用。 -
你能详细回答吗?我对这一切都很陌生
-
@RanjuPatel 正如您在视图中看到的那样,加载委托和数据源是否存在问题?
-
@rokjarc 我确实喜欢这个 NSIndexPath *path = [NSIndexPath indexPathForRow:0 inSection:0]; [[self.tableView 委托] tableView:self.tableView didSelectRowAtIndexPath:path];但它也不起作用
标签: iphone ios didselectrowatindexpath