我想從viewController A設置一個NSString到viewController B.我嘗試使用下面的代碼,但它不工作。準備for segue不讓我設置下一個viewController的NSString
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"segueSubCat"])
{
NSIndexPath *indexPath = [tableViewCat indexPathForSelectedRow];
ViewControllerSubCat *subCatVC = [segue destinationViewController];
subCatVC.cellNameCat = [categories objectAtIndex:indexPath.row];
subCatVC.navigationItem.title = subCatVC.cellNameCat;
}
}
我試過了,每次去第二個視圖時,應用程序都會崩潰。所以我用下面的代碼替換它:
wat = @"wat";
[[segue destinationViewController] setContentsName:wat];
它做了同樣的事情。即它崩潰了。 我不知道我在做什麼錯。
注意:當我拿走prepareForSegue中的代碼時,它就起作用了。
錯誤消息
2014-12-18 15:36:16.382 myApp[1503:42438] -[UINavigationController setCellNameCat:]: unrecognized selector sent to instance 0x7fb9714e7240
2014-12-18 15:36:16.388 myApp[1503:42438] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UINavigationController setCellNameCat:]: unrecognized selector sent to instance 0x7fb9714e7240'
*** First throw call stack:
(
0 CoreFoundation 0x000000010094cf35 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x00000001005e5bb7 objc_exception_throw + 45
2 CoreFoundation 0x000000010095404d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x00000001008ac27c ___forwarding___ + 988
4 CoreFoundation 0x00000001008abe18 _CF_forwarding_prep_0 + 120
5 myApp 0x00000001000b3887 -[ViewController prepareForSegue:sender:] + 343
6 UIKit 0x000000010128b71c -[UIStoryboardSegueTemplate _perform:] + 151
7 UIKit 0x0000000100e21360 -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] + 1242
8 UIKit 0x0000000100e214d4 -[UITableView _userSelectRowAtPendingSelectionIndexPath:] + 219
9 UIKit 0x0000000100d5c331 _applyBlockToCFArrayCopiedToStack + 314
10 UIKit 0x0000000100d5c1ab _afterCACommitHandler + 516
11 CoreFoundation 0x0000000100881dc7 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
12 CoreFoundation 0x0000000100881d20 __CFRunLoopDoObservers + 368
13 CoreFoundation 0x0000000100877b53 __CFRunLoopRun + 1123
14 CoreFoundation 0x0000000100877486 CFRunLoopRunSpecific + 470
15 GraphicsServices 0x0000000103f1b9f0 GSEventRunModal + 161
16 UIKit 0x0000000100d39420 UIApplicationMain + 1282
17 myApp 0x00000001000b4523 main + 115
18 libdyld.dylib 0x0000000102edc145 start + 1
19 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
什麼是崩潰消息? – Paulw11 2014-12-18 23:30:49
給出崩潰錯誤消息。 – kRiZ 2014-12-18 23:37:59