Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/118.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios prepareForSegue调用时不发送参数,导致崩溃_Ios_Iphone_Objective C_Xcode_Uistoryboardsegue - Fatal编程技术网

Ios prepareForSegue调用时不发送参数,导致崩溃

Ios prepareForSegue调用时不发送参数,导致崩溃,ios,iphone,objective-c,xcode,uistoryboardsegue,Ios,Iphone,Objective C,Xcode,Uistoryboardsegue,我的初始视图控制器有两个分段。推送序列连接到单元,模式连接到+UIBarButtonItem 当这是我的prepareForSegue代码的样子时,一切都正常,filePath通过push segue发送,但filePath不通过modal segue - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if ([[segue identifier] isEqualToString:@"showT

我的初始视图控制器有两个分段。推送序列连接到单元,模式连接到+UIBarButtonItem

当这是我的prepareForSegue代码的样子时,一切都正常,filePath通过push segue发送,但filePath不通过modal segue

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:@"showTimes"]) {
        [[segue destinationViewController] setFilePath:filePath];
    }

//    if ([[segue identifier] isEqualToString:@"addEvent"]) {
//        [[segue destinationViewController] setFilePath:filePath];
//    } 
}
如果我取消注释第二条If语句和segue标识符,应用程序就会崩溃。文件路径没有发送到任何地方。我尝试过移动
[[segue destinationViewController]setFilePath:filePath]退出两个if语句,以确保该行已执行,但这也会使我的应用程序崩溃

两个序列在属性中都设置了正确的标识符。但是,我不确定Xcode是否真正意识到设置了正确的标识符,因为当我更改segue类型时,这些更改不会在下次运行应用程序时反映出来


我不知道该做什么。我对Objective-C比较陌生。

添加事件
序列指向导航控制器,而不是视图控制器。取而代之的是,获取视图控制器并在其上设置文件路径:

[[[segue destinationViewController] topViewController] setFilePath:filePath];

addEvent
segue指向导航控制器,而不是视图控制器。取而代之的是,获取视图控制器并在其上设置文件路径:

[[[segue destinationViewController] topViewController] setFilePath:filePath];

如果我也尝试过
else if
,则将第二个if替换为else,但结果与注释掉时相同。我尝试将其更改为
else
,但似乎也不起作用。请检查下面Jason Coco的答案,如果不起作用,请分享日志中显示的崩溃原因。如果我也尝试了
else if
,请将第二个if替换为else,但结果与被注释掉时相同。我尝试将其更改为
else
,但这似乎也不起作用。请检查下面Jason Coco的答案,如果不起作用,请分享日志中显示的崩溃原因。现在编译器的setFilePath有问题:并说“UiViewController”没有可见的@interface声明选择器“setFilePath:”。我导入了目标视图控制器,并且在每个.h文件中声明了filePath。这意味着什么?您必须将UIViewController强制转换为特定的子类,以便编译器了解-setFilePath方法。即,
[(子类名称*)[[segue destinationViewController]topViewController]设置文件路径:文件路径][(子类名称*)[[segue destinationViewController]topViewController]设置文件路径:文件路径]