gpt4 book ai didi

crash - 使用 segue 在 View Controller 之间传递变量

转载 作者:行者123 更新时间:2023-12-01 22:39:34 26 4
gpt4 key购买 nike

我一直在尝试在 View Controller 之间传递变量,但运气不佳。我开始从遇到的问题开始倒退,但现在在继续采取行动时遇到了问题。

无论我使用标识符方法执行segue,还是通过我用来执行计算的按钮进行操作,我都会在调试器中收到以下错误。

如有任何帮助,我们将不胜感激。

2014-02-14 13:59:58.795 BatteryCalculator[6944:70b] Cannot find executable for CFBundle 0x8dbd110 </Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.0.sdk/System/Library/AccessibilityBundles/CertUIFramework.axbundle> (not loaded)
2014-02-14 14:00:00.869 BatteryCalculator[6944:70b] -[DetectorSpacing _setViewDelegate:]: unrecognized selector sent to instance 0x8dd6ff0
2014-02-14 14:00:00.872 BatteryCalculator[6944:70b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[DetectorSpacing _setViewDelegate:]: unrecognized selector sent to instance 0x8dd6ff0'
*** First throw call stack:
(
0 CoreFoundation 0x0173d5e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x014c08b6 objc_exception_throw + 44
2 CoreFoundation 0x017da903 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x0172d90b ___forwarding___ + 1019
4 CoreFoundation 0x0172d4ee _CF_forwarding_prep_0 + 14
5 UIKit 0x00347ecc +[UIViewController setViewController:forView:] + 40
6 UIKit 0x00342921 -[UIViewController setView:] + 511
7 Foundation 0x010edd28 _NSSetUsingKeyValueSetter + 133
8 Foundation 0x010ed253 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 267
9 Foundation 0x0114f70a -[NSObject(NSKeyValueCoding) setValue:forKeyPath:] + 412
10 UIKit 0x004d0a15 -[UIRuntimeOutletConnection connect] + 106
11 libobjc.A.dylib 0x014d27d2 -[NSObject performSelector:] + 62
12 CoreFoundation 0x01738b6a -[NSArray makeObjectsPerformSelector:] + 314
13 UIKit 0x004cf56e -[UINib instantiateWithOwner:options:] + 1417
14 UIKit 0x00341605 -[UIViewController _loadViewFromNibNamed:bundle:] + 280
15 UIKit 0x00341dad -[UIViewController loadView] + 302
16 UIKit 0x003420ae -[UIViewController loadViewIfRequired] + 78
17 UIKit 0x003425b4 -[UIViewController view] + 35
18 UIKit 0x0035c3e2 -[UINavigationController _startCustomTransition:] + 778
19 UIKit 0x003690c7 -[UINavigationController _startDeferredTransitionIfNeeded:] + 688
20 UIKit 0x00369cb9 -[UINavigationController __viewWillLayoutSubviews] + 57
21 UIKit 0x004a3181 -[UILayoutContainerView layoutSubviews] + 213
22 UIKit 0x0ecdc56f -[UILayoutContainerViewAccessibility(SafeCategory) layoutSubviews] + 50
23 UIKit 0x00299267 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355
24 libobjc.A.dylib 0x014d281f -[NSObject performSelector:withObject:] + 70
25 QuartzCore 0x03b4b2ea -[CALayer layoutSublayers] + 148
26 QuartzCore 0x03b3f0d4 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
27 QuartzCore 0x03b3ef40 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 26
28 QuartzCore 0x03aa6ae6 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 294
29 QuartzCore 0x03aa7e71 _ZN2CA11Transaction6commitEv + 393
30 QuartzCore 0x03aa8544 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92
31 CoreFoundation 0x017054ce __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
32 CoreFoundation 0x0170541f __CFRunLoopDoObservers + 399
33 CoreFoundation 0x016e3344 __CFRunLoopRun + 1076
34 CoreFoundation 0x016e2ac3 CFRunLoopRunSpecific + 467
35 CoreFoundation 0x016e28db CFRunLoopRunInMode + 123
36 GraphicsServices 0x036e29e2 GSEventRunModal + 192
37 GraphicsServices 0x036e2809 GSEventRun + 104
38 UIKit 0x0022ed3b UIApplicationMain + 1225
39 BatteryCalculator 0x0000582d main + 141
40 libdyld.dylib 0x01d7b70d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)

目前我不想传递任何内容,我在尝试查找问题时暂时取出了该代码。我所做的就是使用标识符调用 segue 并导致崩溃。我也尝试过从第一个 View Controller 上的按钮调用 segue,但出现同样的错误。

当使用我使用的代码调用segue时:

[self PerformSegueWithIdentifier:@"ResultSegue"发件人:发件人];

最佳答案

这是我在 Segue 之间传递 ManagedObjectContext 的方法

在您将使用prepareForSegue 调用传递数据的类中。 (假设此类有一个名为 _managementObjectContext 的变量,可以将其传递给 segue 类)

要继续的类:

.h 文件:

@property (weak, nonatomic) NSManagedObjectContext *managedObjectContext;

.m 文件:

@synthesize managedObjectContext

对 @synthesize 的调用将产生以下结果:

  • 名为_managementObjectContext的局部变量
  • getManagedObjectContext的方法
  • setManagedObjectContext的方法

另外将以下方法添加到您的类中

// Pass on managedObjectContext
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{

// If the destination VC is able to take the setManagedObjectContext method the current objectContext will be passed along.
if ([segue.destinationViewController respondsToSelector:@selector(setManagedObjectContext:)]) {
[segue.destinationViewController performSelector:@selector(setManagedObjectContext:)
withObject:_managedObjectContext];
} else {

NSLog(@"Segue to controller [%@] that does not support passing managedObjectContext", [segue destinationViewController]);
}
}

然后在我的“类”中接收我所做的数据:在我的 .h 文件中

@property (weak, nonatomic) NSManagedObjectContext *managedObjectContext;

在 .m 文件中我有:

@synthesize managedObjectContext;

它的作用(通过合成)是进行 setManagedObjectContext 和 getManagedObjectContext 调用。即将继续时,我检查以确保目标 Controller 将“响应”此方法,如果是这样,则数据已设置。

清楚吗?

关于crash - 使用 segue 在 View Controller 之间传递变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21781674/

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