我试图将itemSearch
文本字段中的字符串从SearchViewController
传递到我的CriteriaViewController
。我根据这个帖子设置了所有内容:Passing Data between View Controllers。唯一的区别是,我不是传递一个BOOL,而是传递一个字符串。我认为我的错误是我处理这部分的方式:controller.itemSearch == self.itemSearch.text;
错误讯息:
-[CriteriaViewController topViewController]: unrecognized selector sent to instance 0xa99df90
2014-04-17 17:54:20.534 Parse+Storyboard[7095:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason:'-[CriteriaViewController topViewController]: unrecognized selector sent to instance 0xa99df90'
*** First throw call stack:
(
0 CoreFoundation 0x02a751e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x026338e5 objc_exception_throw + 44
2 CoreFoundation 0x02b12243 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x02a6550b ___forwarding___ + 1019
4 CoreFoundation 0x02a650ee _CF_forwarding_prep_0 + 14
5 Parse+Storyboard 0x0000348e -[SearchViewController prepareForSegue:sender:] + 238
6 UIKit 0x01857efa -[UIStoryboardSegueTemplate _perform:] + 156
7 UIKit 0x0141441c -[UIViewController performSegueWithIdentifier:sender:] + 72
8 Parse+Storyboard 0x000032d1 __35-[SearchViewController nextButton:]_block_invoke + 257
9 Parse+Storyboard 0x0007a087 __40-[PFTask thenCallBackOnMainThreadAsync:]_block_invoke_2 + 241
10 libdispatch.dylib 0x036857b8 _dispatch_call_block_and_release + 15
11 libdispatch.dylib 0x0369a4d0 _dispatch_client_callout + 14
12 libdispatch.dylib 0x03688726 _dispatch_main_queue_callback_4CF + 340
13 CoreFoundation 0x02ada43e __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 14
14 CoreFoundation 0x02a1b5cb __CFRunLoopRun + 1963
15 CoreFoundation 0x02a1a9d3 CFRunLoopRunSpecific + 467
16 CoreFoundation 0x02a1a7eb CFRunLoopRunInMode + 123
17 GraphicsServices 0x02cd25ee GSEventRunModal + 192
18 GraphicsServices 0x02cd242b GSEventRun + 104
19 UIKit 0x012f3f9b UIApplicationMain + 1225
20 Parse+Storyboard 0x000028ad main + 141
21 libdyld.dylib 0x038cf701 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
SearchViewController.h:
#import <UIKit/UIKit.h>
#import <Parse/Parse.h>
#import <Parse/PFCloud.h>
#import "CriteriaViewController.h"
@interface SearchViewController : UIViewController
@property (weak, nonatomic) IBOutlet UIButton *nextButtonOutlet;
@end
SearchViewController.m:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([segue.identifier isEqualToString:@"ShowCriteriaSegue"]){
UINavigationController *navController = (UINavigationController *)segue.destinationViewController;
CriteriaViewController *controller = (CriteriaViewController *)navController.topViewController;
controller.itemSearch == self.itemSearch.text;
}
}
CriteriaViewController.h
#import <UIKit/UIKit.h>
#import <Parse/Parse.h>
@interface CriteriaViewController : UIViewController
@property (nonatomic) IBOutlet UITextField *itemSearch;
@end
答案 0 :(得分:2)
这一行:
controller.itemSearch == self.itemSearch.text;
== 用于比较而不是分配,只需用一个等号替换它。
答案 1 :(得分:1)
通过阅读您的崩溃消息:
- [CriteriaViewController topViewController]:无法识别的选择器发送到实例0xa99df90 2014-04-17 17:54:20.534解析+故事板[7095:60b] * 由于未捕获的异常'NSInvalidArgumentException'终止应用程序,原因:' - [CriteriaViewController topViewController]:发送到实例的无法识别的选择器0xa99df90'
好像UINavigationController *navController = (UINavigationController *)segue.destinationViewController;
返回“CriteriaViewController”而不是UINavigationController。
不看故事板文件,很难确认。你应该检查你的故事板文件; segue应该指向包含CriteriaViewController
的UINavigationController