[英]send delegate uitableview to other view controller
i have an uiTableviewController and A uiNavigationController. 我有一个uiTableviewController和uiNavigationController。 Can i implement the delegate DidselectRowAtIndexPath from the UITableViewController in the uiNavigationController so when i select a row in the table there performs an action in the uinavigationcontroller?
我可以在uiNavigationController中的UITableViewController中实现委托DidselectRowAtIndexPath,以便在表中选择一行时在uinavigationcontroller中执行操作吗?
You don't need to subclass UINavigationController and implement there the UITableViewDelegate, the UIViewController responsable of the tableView should be the delegate, and you can just perporm your operation on the navigationController just referting to it from the viewController that implemente the tableView delegate. 您不需要继承UINavigationController的子类并在那里实现UITableViewDelegate,负责tableView的UIViewController应该是委托,并且您可以只对navigationController进行操作,而只需从实现tableView委托的viewController对其进行引用即可。
Just to give you an example: 仅举一个例子:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
RSSItem *item = [_feed objectAtIndex:indexPath.row];
if (item.link) {
WebviewViewController *webViewController = [[WebviewViewController alloc] initWebViewWithLink:item.link title:item.title];
[self.navigationController pushViewController:webViewController animated:YES];
}
}
You can assign the delegate programatically to different viewController over code, it is much cleaner. 您可以通过代码将委托以编程方式分配给不同的viewController,这更加干净。
uitableView.delegate = uinavigationviewcontroller.
But I would implement both datasource and delegate in first view controller and write a custom delegate in the second viewController(which the navigationViewController in your case) and call it on didSelectRowAtIndex: from the first one. 但是我将在第一个视图控制器中实现数据源和委托,并在第二个viewController中编写自定义委托(在您的情况下为navigationViewController),并从第一个视图的didSelectRowAtIndex:调用它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.