Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 为通知生成委托_Ios_Objective C_Delegates_Notifications - Fatal编程技术网

Ios 为通知生成委托

Ios 为通知生成委托,ios,objective-c,delegates,notifications,Ios,Objective C,Delegates,Notifications,假设我有一个整数(hi),它是0。我想要一个消息中显示0的通知。我的代码是: -(IBAction) alert3; { int hi = 0; UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"UIAlertView" message:@"%d"

假设我有一个整数(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的参数格式化程序,必须在逗号后传递

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

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

delegate:nil

或者自己控制它。

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

这样做:

 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"UIAlertView"
                                            message:[NSString stringWithFormat:@"%d", hi]
                                           delegate:self
                                  cancelButtonTitle:@"Ok"
                                  otherButtonTitles: nil];
%d是int的参数格式化程序,必须在逗号后传递

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

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

delegate:nil

或者自己控制它。

正确的实施!!正确的实现!!