我有一些代碼應該返回一個NSString。相反,它有時會返回一個NSArrayReverseEnumerator。這會導致無法識別的選擇器發送到實例異常。對象返回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文本屬性返回什麼這引起異常。
唯一的例外是:
- [__ 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樣子這通常不能在調試器中重現,但在異常時看不到它的樣子:
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?
請NSLog ** self.userObject ** –
'tFirstName'定義在哪裏? –
右上方說NSString * tFirstName = nil; –