简体   繁体   English

发送委托uitableview到其他视图控制器

[英]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.

相关问题 当数据源和委托与View Controller分开时,如何将Table View的单击项发送到其他View Controller - How to send clicked item of Table View to other view controller when datasource and delegate are separate from View Controller 使用来自iOS Swift中其他视图控制器的委托来更新UITableView中的“ DetailTextLabel.text” - update “DetailTextLabel.text” in a UITableView using delegate from other view-controller in iOS swift 委托发送回值并推送弹出视图控制器 - Delegate send value back and push pop view controller 即使视图控制器是“子”控制器,如何使用委托和数据源更新UITableView? - How to make UITableView updating with delegate and datasource even if the view controller is a “child” controller? Swift Ios将没有自我的委托设置为其他视图控制器 - Swift Ios setting delegate without self as other view controller Swift-未调用其他视图控制器中的函数(协议/委托) - Swift - Function in other view controller is not being called (protocol / delegate) 将对象发送到UITableView控制器 - Send object to UITableView controller 使用通过委托从另一个视图控制器传递的数据将行插入到UITableView中 - Inserting rows into UITableView using data that's passed from another view controller via delegate 视图控制器中的UITableView - UITableView inside a view controller 将数组从1个视图控制器发送到2个其他单独的视图控制器 - Send array from 1 view controller to 2 other separate view controllers
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM