首先感謝我的英語。Xcode 4:我如何在兩個不同的類中使用int?
我正在創建一個應用程序,用於統計您在按鈕內部觸摸的次數。該應用程序被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不是故事情節 感謝您的時間!
將它放在我的情況下工作嗎? ,因爲newValue等於第二個視圖中的滑塊的值 – yeker3 2012-04-18 18:36:23