ios - 在 MMDrawerController 上传递数据

标签 ios iphone objective-c uiviewcontroller uinavigationcontroller

我正在使用 MMDrawerController在我的应用程序中。当我想将数据从 MMExampleLeftSideDrawerViewController 传递到 MMExampleCenterTableViewController 时,我做不到。

您可以在源代码中看到 MMExampleLeftSideDrawerViewController 和 MMExampleCenterTableViewController 类。 源代码:link

我添加了这段代码:

MMExampleCenterTableViewController.h

-(void)doSomethingUseful:(NSString *)data;

MMExampleCenterTableViewController.m

-(void)doSomethingUseful:(NSString *)data
{
    NSLog(@"dosometing useful %@",data);
}

MMExampleLeftSideDrawerViewController.m

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    MMExampleCenterTableViewController * mycenterController=(MMExampleCenterTableViewController *)self.mm_drawerController.centerViewController;

    [mycenterController doSomethingUseful:@"mydata"];

    //...........
}

当我点击 MMExampleLeftSideDrawerViewController 上的表格 View 时,出现问题,您可以在源代码中看到。

问题日志是: 'NSInvalidArgumentException',原因:'-[MMNavigationController doSomethingUseful:]: 无法识别的选择器发送到实例

所以它不是同一个对象的类。( MMExampleCenterTableViewController * mycenterController=(MMExampleCenterTableViewController *)self.mm_drawerController.centerViewController; )。

如何将数据发送到 MMExampleCenterTableViewController ?

最佳答案

看起来 self.mm_drawerController.centerViewController 是一个导航 Controller 。你想要的可能是它的 topViewController,所以试试这个:

 MMExampleCenterTableViewController * mycenterController= [(MMNavigationController *)self.mm_drawerController.centerViewController topViewController];

关于ios - 在 MMDrawerController 上传递数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20197967/

相关文章:

iphone - ARC 和释放内存

iphone - 自定义注释单击时查看图像恢复为图钉

ios - 核心数据 : Unable to load class named "CDAccount"

iOS UIImage 转换为固定内存大小

ios - iOS : EAWiFiUnconfiguredAccessoryBrowser will detect unconfigured accessories only once 无线配件配置

ios - 动态调整 UITextField 大小同时在输入文本时保持其居中的正确方法是什么?

ios - 当用户在 UITextField 中键入时,将逗号添加到数字值

iphone - 确定 CGPoint 是否在图像区域内

ios - 在 TableView 单元格中显示来自 Firebase 的数据

ios - 警报 addAction(action) 给我一条错误消息,指出操作是未解析的标识符