1

假设我有一个整数 (hi),即 0。我希望通知在消息中显示 0。我的代码是:

-(IBAction) alert3;
{
    int hi = 0;

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"UIAlertView"
                                            message:@"%d"
                                           delegate:hi
                                  cancelButtonTitle:@"Ok"
                                  otherButtonTitles: nil];

然后我得到一个错误:

“不兼容的整数到指针转换将'int'发送到'id'类型的参数”

4

1 回答 1

1

您的实施不完整。您需要将消息添加为字符串。

做这个:

 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"UIAlertView"
                                            message:[NSString stringWithFormat:@"%d", hi]
                                           delegate:self
                                  cancelButtonTitle:@"Ok"
                                  otherButtonTitles: nil];

%d 是 int 的参数格式化程序,您必须在逗号之后传递

关于委托,委托是将响应 UIAlertViewDelegate 中定义的消息的类(例如,当用户触摸按钮时)。

如果您不想控制它,只需将其设置为 null:

delegate:nil

或者自己去控制它。

于 2013-07-15T12:56:07.023 回答