首先对不起我的英语。
我正在创建一个应用程序来计算您在按钮内触摸的次数。该应用程序由 UITabBarController 划分:在第一个视图(类:ViewController)中有一个按钮和一个显示“int”值的标签(int counter;),问题是我想设置一个最大数量,因此当您触摸按钮 50 次时,会出现一个 alertView。我想让这个最大数量灵活,以便您可以通过 tabBar 的第二个视图中的滑块调整它。
这是代码:
视图控制器.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController{
int counter;
IBOutlet UILabel *counterLabel;
}
-(IBAction)counter:(id)sender;
-(IBAction)Reset:(id)sender;
@end
视图控制器.m
#import "ViewController.h"
@implementation ViewController
-(IBAction)counter:(id)sender{
if (counter < end) // in spite of end, I want to put Max (declared in AjustesView.h)
{
counter = counter+1;
counterLabel.text = [NSString stringWithFormat:@"%i", Jugador1];
}else
{
UIAlertView *alerta = [[UIAlertView alloc] initWithTitle:@"Alerta!" message:@"Ha llegado a 100 cliks" delegate:self cancelButtonTitle:@"Aceptar" otherButtonTitles:nil, nil];
[alerta show];
[alerta release];
}
}
-(IBAction)Reset:(id)sender{
counter = 0;
counterLabel.text = [NSString stringWithFormat:@"%i", counter];
}
调整视图.h
@interface AjustesView : UIViewController{
IBOutlet UISlider *maxSlider;
IBOutlet UILabel *maxLabel;
int max;
}
@property (nonatomic, retain) IBOutlet UISlider *maxSlider;
-(IBAction)AdjustmentOfMaximum:(id)sender;
@end
AjustesView.m
#import "AjustesView.h"
@implementation AjustesView
@synthesize maxSlider;
-(IBAction)AdjustmentOfMaximum:(id)sender{
max = self.maxSlider.value;
maxLabel.text = [NSString stringWithFormat:@"%i", max];
}
IB 文件是 .xib 而不是情节提要 感谢您抽出宝贵时间!