开发者

iPhone SDK simple alert message question

开发者 https://www.devze.com 2022-12-26 10:26 出处:网络
char asd=\'a\'; UIAlertView *alert = [[UIAlertView allo开发者_JAVA技巧c] initWithTitle:@\"Are you sure?\" message:asd
char asd='a';
UIAlertView *alert = [[UIAlertView allo开发者_JAVA技巧c] initWithTitle:@"Are you sure?" message:asd
               delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];
[alert show];
[alert release];

above code not compiling in iPhone simulator. Why is that? :)


You're trying to pass a char where an NSString is expected. Read up on Objective-C and th Cocoa/Cocoa Touch documentation.

To fix your issue, try this:

NSString *asd = @"a";
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Are you sure?" message:asd
               delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];
[alert show];
[alert release];


  1. You don't compile in the iPhone simulator, you compile on your mac.
  2. Do you get an error message?
  3. The message parameter should be an NSString, not a char?


replace

char asd='a';

With

NSString *asd=@"a";

It should compile after it...

0

精彩评论

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