开发者

UIAlertView adding NSString

I want to add string to message of my UIAlertView


-(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];

}

but开发者_Python百科 it throws


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'

so how can i add string variable to the message of UIAlertView?


An NSException won't suddenly turn into an NSString when you cast it as one. NSException has a property called reason, that's the one you need. Use it like this: NSString *reason = exp.reason;

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜