0
你可能會認爲這將返回一個NSString:爲什麼我沒有從NSStringFromClass獲取NSString?
NSString *class = NSStringFromClass([[_array objectAtIndex:([_array count] -2)] class]);
NSLog(@"Is a kind of NSString: %@", ([[_class classForCoder] isSubclassOfClass:[NSString class]])? @"Yes" : @"No");
if ([class isEqualToString:@"MapViewController"]) {
[_appDelegate.navController0 pushViewController:_userListController animated:YES];
} else {
[_appDelegate.navController3 pushViewController:_userListController animated:YES];
}
但由於某些原因,它不,導致此故障:
Is a kind of NSString: No
-[NSKeyValueObservationInfo isEqualToString:]: unrecognized selector sent to instance 0x6e69080
即使當我嘗試這個辦法:
NSString *class = (NSString *)[[_array objectAtIndex:([_array count] -2)] class];
它仍然不會返回一個NSString,導致此崩潰:
Is a kind of NSString: No
+[MapViewController isEqualToString:]: unrecognized selector sent to class 0xd4460
我知道進去了,最後一個例子有一點點延伸,但我對於爲什麼沒有從任何一個返回的NSString得到一個相當無知?
'class'和'_class'之間的混合只是一個錯字? – 2012-07-21 14:16:13
是的,它是。修正它 – 2012-07-21 14:32:15
你確定這個索引有一個對象嗎?你是否試過'nslog(@「%@」,class)'或者你是否用調試器檢查過它? – Bastian 2012-07-21 15:46:09