我正在下载一个 NSManagedObject。将 NSString 分配给该对象的 valueForKey@"username"。接下来,我将该字符串分配给 UITableView 中的 cell.textLabel.text 并且出现异常。
以下是引发异常的代码:
-(NSString *)fetchUserName
{
if ([fetchedUserNameObject objectAtIndex:0]!= NULL)
{
recipientUser = (User*)(fetchedUserNameObject);
NSString *userName = (NSString*)[recipientUser valueForKey:@"username"];
return userName;
}
}
......
NSString *recipientUserName = [self fetchUserName]
……
- (IBAction)reviewButtonPressed:(UIBarButtonItem *)sender
{
NSLog(@"Recipient UserName from Review Button %@", recipientUserName);
PDReviewVC *modalVC = [self.storyboard instantiateViewControllerWithIdentifier:@"pdReview"];
UINavigationController *navBar=[[UINavigationController alloc]initWithRootViewController:modalVC];
modalVC.recipientUserName= self.recipientUserName;
[self presentViewController:navBar animated:YES completion:NULL];
}
日志
2013-08-30 11:51:49.393 Time[1188:c07] Recipient UserName from Review Button (
iphone3gs
)
现在在 PDReviewVC 中:
。H
@property (nonatomic, retain) NSString * recipientUserName;
.m
@synthesize recipientUserName;
... //cellForRowAtIndexPath
if (indexPath.section == 0)
{
cell.textLabel.text = recipientUserName;
}
我在 cell.textLabel.text = recipientUserName; 上收到以下错误:
2013-08-30 11:51:54.679 Time[1188:c07] -[__NSArrayI isEqualToString:]: unrecognized selector sent to instance 0xb889390
2013-08-30 11:53:53.303 Time[1188:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI isEqualToString:]: unrecognized selector sent to instance 0xb889390'
*** First throw call stack:
更新
NSLog 用于以下代码:
if ([fetchedUserNameObject objectAtIndex:0]!= NULL)
{
recipientUser = (User*)(fetchedUserNameObject);
NSLog(@"User %@", recipientUser);
NSString *userName = (NSString*)[recipientUser valueForKey:@"username"];
NSLog (@"userName from fetchUserName: %@", userName);
NSLog(@"%@", userName);
return userName;
}
else return NULL;
NS日志:
2013-08-30 12:36:29.495 Time[1341:c07] User (
"<User: 0xa55cd60> (entity: User; id: 0xa5a0ae0 <x-coredata://3B273CFB-1CAA-4FA0-95DC-BA9420219380-1341-000007F42366B21A/User/piphone3gs> ; data: <fault>)"
)
2013-08-30 12:36:29.496 Time[1341:c07] userName from fetchUserName: (
iphone3gs
)
2013-08-30 12:36:29.496 Time[1341:c07] (
iphone3gs
)