gpt4 book ai didi

ios - 将数据从 VC 传递到 VC segue

转载 作者:行者123 更新时间:2023-11-29 12:45:29 32 4
gpt4 key购买 nike

我正在使用这段代码将一个对象传递给另一个 View Controller 。

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([segue.identifier isEqualToString:@"Detail"]){
UINavigationController *navController = (UINavigationController *)segue.destinationViewController;
DetailedViewController *controller = (DetailedViewController *)navController.topViewController;
controller.clipping = [pasteBoardArray objectAtIndex:_row];
}
}

在线:

DetailedViewController *controller = (DetailedViewController *)navController.topViewController;

我得到一个冗长的异常

2014-05-20 18:46:39.752 SWTableViewCell[8370:60b] -[DetailedViewController topViewController]: unrecognized selector sent to instance 0x10c7169e0
2014-05-20 18:46:39.756 SWTableViewCell[8370:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[DetailedViewController topViewController]: unrecognized selector sent to instance 0x10c7169e0'
*** First throw call stack:
(
0 CoreFoundation 0x0000000102667495 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x00000001016c699e objc_exception_throw + 43
2 CoreFoundation 0x00000001026f865d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x0000000102658d8d ___forwarding___ + 973
4 CoreFoundation 0x0000000102658938 _CF_forwarding_prep_0 + 120
5 SWTableViewCell 0x000000010000d91c -[ViewController prepareForSegue:sender:] + 204
6 UIKit 0x00000001004f4c73 -[UIStoryboardSegueTemplate _perform:] + 134
7 SWTableViewCell 0x000000010000c4be -[ViewController tableView:didSelectRowAtIndexPath:] + 350
8 SWTableViewCell 0x00000001000089ae -[SWTableViewCell selectCell] + 798
9 SWTableViewCell 0x000000010000864b -[SWTableViewCell scrollViewTapped:] + 171
10 UIKit 0x0000000100362fc2 _UIGestureRecognizerSendActions + 188
11 UIKit 0x0000000100361f28 -[UIGestureRecognizer _updateGestureWithEvent:buttonEvent:] + 357
12 UIKit 0x00000001003662d9 ___UIGestureRecognizerUpdate_block_invoke + 53
13 UIKit 0x0000000100366261 _UIGestureRecognizerRemoveObjectsFromArrayAndApplyBlocks + 257
14 UIKit 0x000000010035e337 _UIGestureRecognizerUpdate + 93
15 UIKit 0x0000000100072a15 -[UIWindow _sendGesturesForEvent:] + 928
16 UIKit 0x00000001000736d4 -[UIWindow sendEvent:] + 909
17 UIKit 0x000000010004b29a -[UIApplication sendEvent:] + 211
18 UIKit 0x0000000100038aed _UIApplicationHandleEventQueue + 9579
19 CoreFoundation 0x00000001025f6d21 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
20 CoreFoundation 0x00000001025f65f2 __CFRunLoopDoSources0 + 242
21 CoreFoundation 0x000000010261246f __CFRunLoopRun + 767
22 CoreFoundation 0x0000000102611d83 CFRunLoopRunSpecific + 467
23 GraphicsServices 0x00000001025c6f04 GSEventRunModal + 161
24 UIKit 0x000000010003ae33 UIApplicationMain + 1010
25 SWTableViewCell 0x0000000100002763 main + 115
26 libdyld.dylib 0x000000010607f5fd start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

作为旁注,我是在 UINavigationBarController 中完成这一切的。我需要做的就是将 objectAtIndex:_row 传递给 DetailedViewController 中的 _clipping 属性。

最佳答案

如果您的两个 View Controller 之间没有导航 Controller ,请使用以下代码:

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([segue.identifier isEqualToString:@"Detail"]){
DetailedViewController *controller = (DetailedViewController *)[segue destinationViewController];
controller.clipping = [pasteBoardArray objectAtIndex:_row];
/* ... */
}
}

仅当您的两个 View Controller 之间有一个导航 Controller 时才使用以下代码:

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([segue.identifier isEqualToString:@"Detail"]){
UINavigationController *navController = (UINavigationController *)segue.destinationViewController;
DetailedViewController *controller = (DetailedViewController *)navController.topViewController;
controller.clipping = [pasteBoardArray objectAtIndex:_row];
/* ... */
}
}

关于ios - 将数据从 VC 传递到 VC segue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23772263/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com