2010-07-15 73 views
2

我想字符串添加到我的UIAlertView中UIAlertView中添加的NSString


-(void) errorState:(NSException *) exp 
{ 
    NSLog(@"Error State Blood Level3 %@",exp); 
    NSString * myString = (NSString*)exp; 
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:myString delegate:self cancelButtonTitle:@"Go to the main menu" otherButtonTitles:nil]; 
    [alert show]; 
    [alert release];

}

的消息,但它拋出


2010-07-15 12:48:34.721 kndFrameV02[7955:207] -[NSException isEqualToString:]: unrecognized selector sent to instance 0x707b2e0 
2010-07-15 12:48:34.724 kndFrameV02[7955:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSException isEqualToString:]: unrecognized selector sent to instance 0x707b2e0' 

所以,我怎麼能字符串變量添加到UIAlertView中的消息?

回答

7

NSException當您將其作爲一個投影時,它不會突然變爲NSStringNSException有一個名爲reason的屬性,這是你需要的。像這樣使用它:NSString *reason = exp.reason;