【问题标题】:Crash when passing string传递字符串时崩溃
【发布时间】:2016-10-14 09:32:34
【问题描述】:

我的代码在传递字符串参数时崩溃。

有人可以帮我排序吗? :

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

    NSIndexPath *indexPath = (NSIndexPath *)sender;

    if ([[segue identifier] isEqualToString:@"abc"]) {

        MyVC *myvc = [segue destinationViewController];
        myvc.itemstring=@"dsdsds";

    }

}

错误

-[UIViewController itemstring:]:无法识别的选择器发送到实例 0x7fc89b0028d0

2016-10-14 14:54:24.118 Myapp[7824:109039] *** 由于应用程序终止 未捕获的异常“NSInvalidArgumentException”,原因: '-[UIViewController itemstring:]: 无法识别的选择器发送到 实例 0x7fc89b0028d0'

我的VC

#import <UIKit/UIKit.h>

@interface MyVC : UIViewController {
    NSString* itemstring;    
}

@property (nonatomic, strong) NSString* itemstring;

@end

【问题讨论】:

  • 用 MyVC 控制器更新你的问题
  • 显示错误。
  • NSIndexPath *indexPath = (NSIndexPath *)sender 有什么用?在这里
  • 崩溃日志中有什么内容?哪条线路崩溃了?
  • [segue destinationViewController] 似乎是 UIViewController 对象而不是 MyVC 对象。在 InterfaceBuilder 中,您没有将类设置为 UIViewControllerMyVC

标签: ios objective-c iphone


【解决方案1】:

错误中的行...

-[UIViewController itemstring:]:无法识别的选择器发送到实例 0x7fc89b0028d0

这表明转场的目的地是UIViewController,而不是MyVC

您可能没有在情节提要中正确设置子类。

你可以在这里更新...

通过将Class 更改为MyVC

【讨论】:

  • 传说中的东西+1
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-09-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多