我正在 Xcode 上创建一个应用程序,我希望在他们单击按钮 100 次时显示警报视图,但由于某种原因,当我单击按钮 100 次时没有任何反应,我会向您显示我在应用程序中拥有的所有代码目前以及我在 xib 中所做的事情以及与希望你们提供帮助的相关内容。
#import <UIKit/UIKit.h>
int counter;
@interface ViewController : UIViewController {
IBOutlet UILabel *count;
}
-(IBAction)plus;
-(IBAction)minus;
-(IBAction)zero;
@end
执行
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void) buttonAction {
counter++;
if(counter == 100)
[self showAlert];
}
- (void) showAlert {
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Tile"
message:@"This is the message"
delegate:nil
cancelButtonTitle:@"Dismiss"
otherButtonTitles:nil];
[alert show];
}
-(IBAction)plus {
counter=counter + 1;
count.text = [NSString stringWithFormat:@"%i",counter];
}
-(IBAction)minus {
counter=counter - 1;
count.text = [NSString stringWithFormat:@"%i",counter];
}
-(IBAction)zero {
counter=0;
count.text = [NSString stringWithFormat:@"%i",counter];
}
- (void)viewDidLoad {
counter=0;
count.text = @"0";
[super viewDidLoad];
}
- (void)viewDidUnload {
[super viewDidUnload];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
@end
这就是我拥有的所有代码,我遇到的问题是计数器工作正常,就在我达到 100 时,没有任何反应这是图像
并且没有警报