【发布时间】:2012-04-18 18:21:34
【问题描述】:
首先对不起我的英语。
我正在创建一个应用来计算您在按钮内触摸的次数。该应用程序由 UITabBarController 划分:在第一个视图(类:ViewController)中有一个按钮和一个显示“int”值的标签(int counter;),问题是我想设置一个最大数量,因此当您触摸该按钮 50 次时,会出现一个 alertView。我想让这个最大数量变得灵活,这样你就可以通过 tabBar 的第二个视图中的滑块来调整它。
代码如下:
ViewController.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController{
int counter;
IBOutlet UILabel *counterLabel;
}
-(IBAction)counter:(id)sender;
-(IBAction)Reset:(id)sender;
@end
ViewController.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];
}
AjustesView.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 而不是故事板 感谢您的宝贵时间!
【问题讨论】:
标签: objective-c ios sdk uitabbarcontroller xcode4.2