假设我有一个整数 (hi),它是 0。我想要一个在消息中说 0 的通知。我的代码是:
-(IBAction) alert3;
{
int hi = 0;
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"UIAlertView"
message:@"%d"
delegate:hi
cancelButtonTitle:@"Ok"
otherButtonTitles: nil];
然后我得到一个错误:
“将‘int’发送到‘id’类型的参数的指针转换不兼容的整数”
最佳答案
您的实现不完整。您需要将消息添加为字符串。
这样做:
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"UIAlertView"
message:[NSString stringWithFormat:@"%d", hi]
delegate:self
cancelButtonTitle:@"Ok"
otherButtonTitles: nil];
%d 是一个 int 的参数格式化器,你必须在逗号之后传递
关于委托(delegate),委托(delegate)是将响应 UIAlertViewDelegate 中定义的消息的类(例如,当用户触摸按钮时)。
如果你不想控制它,只需将它设置为空:
delegate:nil
或者 self 控制。
关于ios - 为通知创建委托(delegate),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17654781/