Ios 为通知生成委托
假设我有一个整数(hi),它是0。我想要一个消息中显示0的通知。我的代码是: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"
-(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
或者自己控制它。正确的实施!!正确的实现!!