我在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没有任何反应继承人的图像
并且没有提示
使用这种方法,我无法得到我在101上的情况,并且我按下减号按钮 – 2012-07-09 10:46:12
这是真的。我没有意识到你会希望作为一种选择。在这种情况下,我会建议将'if(counter == 100){[self showAlert];}'添加到减号函数的末尾。我相信这可能是添加所需功能的最简单方法。如果你想把它扩展到不同的按钮和方法,我会建议创建一个函数来检查它是否为100,但对于只有两个按钮,一个全新的方法看起来像是矫枉过正。 – 2012-07-09 16:04:21
@ChanceR。您好再次我想添加一个按钮,但它不会很好点将说“评价这个应用程序”,你可以帮助哥们吗? – Picm 2012-07-12 14:01:34