简体   繁体   English

iPhone SDK简单警报消息问题

[英]iPhone SDK simple alert message question

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

above code not compiling in iPhone simulator. 以上代码无法在iPhone模拟器中编译。 Why is that? 这是为什么? :) :)

You're trying to pass a char where an NSString is expected. 您正在尝试传递一个预期使用NSStringchar Read up on Objective-C and th Cocoa/Cocoa Touch documentation. 阅读Objective-C和Cocoa / Cocoa Touch文档。

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. 您无需 iPhone模拟器中进行编译,而是在Mac上进行编译。
  2. Do you get an error message? 您是否收到错误消息?
  3. The message parameter should be an NSString , not a char ? message参数应该是NSString ,而不是char

replace 更换

char asd='a';

With

NSString *asd=@"a";

It should compile after it... 它应该在之后编译...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM