我正在为 iOS 设备创建一个应用程序,但在下面的图像中我有一些错误
正如你所看到的,但我只是有错误感觉,我添加了链接的代码(苹果,谷歌,雅虎,
我不确定出了什么问题,但如果您能提供帮助并告诉我需要更改哪些内容来阻止这些错误,我将非常感激。
<小时/>正如你所看到的,下面只有一个显示警报代码,但我在 Xcode 中有另外 10 个,我只是不想占用所有空间,但我已经将它们命名为
showAlertOO 显示警报1 显示警报2 显示警报3 显示警报4 显示警报5 显示警报6 显示警报7 显示警报8 显示警报9
如果你明白我的意思
- (void) showAlert {
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"hello"
message:@"whats you name"
delegate:nil
cancelButtonTitle:@"Dismiss"
otherButtonTitles:@"apple", @"google" , @"yahoo", nil];
[alert show];
<小时/>
好吧,这是我添加的代码,让我的按钮正常工作,然后这就是导致它们错误的原因。
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 1) { [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.apple.com/uk"]];
}
if (buttonIndex == 2) { [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.google.com"]];
}
if (buttonIndex == 3) { [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.yahoo.com"]];
}
<小时/>
下面的所有代码都很好,我这里没有错误,我只是想让你们看看我的设置
-(IBAction)plus {
counter=counter + 1;
count.text = [NSString stringWithFormat:@"%i",counter];
if(counter == 100)
[self showAlert];
if(counter == 500)
[self showAlert00];
if(counter == 1000)
[self showAlert1];
if(counter == 2500)
[self showAlert2];
if(counter == 5000)
[self showAlert3];
if(counter == 7500)
[self showAlert4];
if(counter == 10000)
[self showAlert5];
if(counter == 15000)
[self showAlert6];
if(counter == 20000)
[self showAlert7];
if(counter == 25000)
[self showAlert8];
if(counter == 30000)
[self showAlert9];
if(counter == 35000)
[self showAlert10];
}
-(IBAction)zero {
counter=0;
count.text = [NSString stringWithFormat:@"%i",counter];
}
- (void)viewDidLoad {
counter=0;
count.text = @"0";
[super viewDidLoad];
}
非常感谢您抽出时间。
最佳答案
您在实际使用选择器“showAlert”...“showAlert10”之前是否声明了它们? 如果没有,您可以在私有(private)类别中声明它们(位于 .m 文件的顶部)。
顺便说一句...我强烈建议您使用描述性名称,而不是“showAlert5”。这最终可以为你节省一些来回的时间......而且不仅仅是为了这个,我的意思是,在你的代码中的任何地方。
关于ios - UIAlertView代码错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11484640/