ios - 无法将数据设置为 prepareForSegue 中的数组

标签 ios objective-c uinavigationcontroller nsarray

我正在使用 Objective-C,我想为另一个 View Controller 复制一个数组并推送它。这是我的代码:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

    if ([segue.identifier isEqualToString:@"comment"]){
        commentViewController *vc = segue.destinationViewController;
        vc.comments = [[NSArray alloc]initWithArray:comments];
    }
}

但它不起作用。我在 Xcode 中得到了这个:

2015-12-06 16:27:45.802 net[1244:29117] -[UIViewController setComments:]: 无法识别的选择器发送到实例 0x7ff8d34eb720 2015-12-06 16:27:45.807 net[1244:29117] *** 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[UIViewController setComments:]: 无法识别的选择器发送到实例 0x7ff8d34eb720”

有人可以帮助我吗?

最佳答案

在 Storyboard 中选择目标 View Controller 。并在身份检查器中确保您的目标 vc 是您的自定义类,如图所示。

enter image description here

关于ios - 无法将数据设置为 prepareForSegue 中的数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34115506/

相关文章:

iphone - 编辑完成后是否有 `setEditing` 的倒数?

ios - 如何将应用程序音量与系统音量(iOS设备音量物理键)分开设置?

ios - 将光标设置到 UITextView 内的开头

ios - 为什么我无法保存应用内购买?

ios - 无法禁用复制 UIWebView

iOS 有条件地显示 View

objective-c - xcode 7 Objective c 警告 - 将 Null 传递给需要非空参数的被调用方

swift - 过渡到上一个 View 时呈现模式

ios - PresentingViewController 被设置为 nil

ios - 我们需要为登录编写 UI 测试用例吗?