gpt4 book ai didi

objective-c - 对象返回 NSArrayReverseEnumerator。导致无法识别的选择器发送到实例

转载 作者:行者123 更新时间:2023-12-01 16:56:48 25 4
gpt4 key购买 nike

我有一些应该返回 NSString 的代码。相反,它有时会返回一个 NSArrayReverseEnumerator。这会导致无法识别的选择器发送到实例异常。

NSString *tFirstName = nil;
NSString *tUsername = ((NSString*)[self.userObject objectForKey:USER_NAME]).length > 0 ? [self.userObject objectForKey:USER_NAME] : [self.userObject objectForKey:USER_USERNAME];
NSRange spaceRange = [tUsername rangeOfString:@" "];
if (spaceRange.location == NSNotFound) {
tFirstName = tUsername;
} else {
tFirstName = [tUsername substringToIndex:spaceRange.location];
}
return tFirstName;

然后,我将 UITextField 文本属性设置为返回的导致异常的内容。

异常(exception)是:

-[__NSArrayReverseEnumerator isEqualToString:]:无法识别的选择器发送到实例 0xf1b8190

这是堆栈跟踪的最后几行:
 CoreFoundation 0x381208bf __exceptionPreprocess + 163
1 libobjc.A.dylib 0x31c061e5 objc_exception_throw + 33
2 CoreFoundation 0x38123acb -[NSObject doesNotRecognizeSelector:] + 175
3 CoreFoundation 0x38122945 ___forwarding___ + 301
4 CoreFoundation 0x3807d680 _CF_forwarding_prep_0 + 48
5 UIKit 0x354dc20d -[UILabel setText:] + 45
6 Trivial 0x000873c9 -[vcGameOver viewDidLoad] (vcGameOver.m:45)
7 UIKit 0x355117ff -[UIViewController view] + 167

userObject 通常看起来像这样,还不能在调试器中重现,还没有看到它在异常时的样子:

用户对象看起来像这样:
(PFUser *) $1 = 0x0be86fb0 <PFUser:MTsJR1DKuS> {
answeredCorrect = "<PFRelation: 0xa847f30>";
centsEarned = "-2353";
centsPaidFor = 5000;
centsUsed = 4193;
correctAnswers = 1454;
earnedCoinDate = "2012-06-12 19:42:44 +0000";
eloRating = 1262;
iq = 119;
lastPlayedDate = "2012-06-12 19:15:46 +0000";
locale = en;
losses = 10;
name = "Matt Hudson";
status = 0;
username = Inturbidus;
wins = 8;
wrongAnswers = 1157;
}

我的问题是,我上面的代码中的哪一行可能返回一个 NSArrayReverseEnumerator?

最佳答案

您可能有一个悬空指针,而其他一些对象(在这种情况下,可能是 Apple 私有(private)的 __NSArrayReverseEnumerator )蹲在内存中您过早释放 NSString 的位置。曾经的实例。

我建议打开僵尸( NSZombieEnabled )并查看您是否收到“message sent to deallocated instance ”错误消息,而不是您收到的错误消息。

关于objective-c - 对象返回 NSArrayReverseEnumerator。导致无法识别的选择器发送到实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11003558/

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