NSInvalidArgumentException发送到实例的无法识别的选择器
我正在开发一个twitter查看应用程序,并且遇到了将数据从单元格传递到详细视图的问题。每次我点击单元格我的程序终止此错误。NSInvalidArgumentException发送到实例的无法识别的选择器
2015-09-04 12:18:34.298 twitterView2[10580:872508] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[TwitterPostInfo objectForKey:]: unrecognized selector sent to instance 0x7f9fb261f890'
*** First throw call stack:
(
0 CoreFoundation 0x000000010527fc65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000104f18bb7 objc_exception_throw + 45
2 CoreFoundation 0x00000001052870ad -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x00000001051dd13c ___forwarding___ + 988
4 CoreFoundation 0x00000001051dccd8
很难知道肯定没有看到你在哪里分配这个类的tweetDetail属性,但它会出现,你要指定类型TwitterPostInfo,不NSDictionary中的对象。检查你在哪里设置这个属性,并确保它是正确的类型。
或者,如果您打算传递TwitterPostInfo对象,则必须更改tweetDetail的类型以匹配。当然,你必须更新你的数据访问方式(我假设它是一个自定义类,我无法通过Google找到任何东西)。
编辑:
看到您的prepareForSegue方法后,我的猜测是,你打算沿着TwitterPostInfo对象,而不是一个NSDictionary通过。如果这是真的,你会想把tweetDetail的类型从NSDictionary改为TwitterPostInfo。然后,取决于你是如何构建你的课堂,而不是使用[self.tweetDetail objectForKey:@"text"]
和[self.tweetDetail objectForKey:@"created_at"]
,你会想要使用相当于self.tweetDetail.text
和self.tweetDetail.createdAt
的东西。
尝试此TwitterDetailVC.h:
#import <UIKit/UIKit.h>
#import "TwitterPostInfo.h"
@interface TwitterDetailVC : UIViewController
@property (strong, nonatomic) TwitterPostInfo *tweetDetail;
@end
这对于TwitterDetailVC.m的viewDidLoad方法
- (void)viewDidLoad {
[super viewDidLoad];
self.tweetTextLabel.text = self.tweetDetail.tweetText;
self.tweetTimeLabel.text = self.tweetDetail.timeDate;
}
无处不在,我已经使用tweetDetail在我上面发布的代码。我拉的所有对象都是字符串。这是一个自定义类 –
当然,你必须从某处分配tweetDetail属性。如果不是,你为什么要从viewDidLoad中获取数据?你能告诉我你是如何将数据传递给这个类的? – travisjsmith
我对编程仍然陌生,但数据正在传递中,不是吗? –
最简单的方式找到问题的位置在Xcode去断点导航(Command + 7)。点击底部的+,然后选择“添加异常断点”。现在,当你运行你的程序时,它将在发生异常时停止并向你显示堆栈跟踪而不是“未捕获的异常”
当发布时,你应该使用花括号来格式化代码。 – Adrian
我的歉意。感谢您纠正我的帖子,我很新的stackoverflow –