UIButton を作成しました。実際には、いくつかのボタンがあり、それらを初期化して、
-(void)viewDidLoad
方法。私の問題は、私が作成したメソッドにそれらを接続することです。ボタンのタグの番号を特定の状況の名前に置き換える typedef 列挙型を作成しました。これが問題なのか何なのかわかりませんが、ボタンを押しても機能しない理由がわかりません。私のコードは以下です。
私の列挙型:
typedef enum {
DiseasesStrepThroat = 1,
DiseasesFlu = 2,
DiseasesChickenPox = 3,
DiseasesSmallPox = 4,
DiseasesMeasels = 5,
DiseasesCommonCold = 6
} DiseasesTagNumber;
すべての UIButton オブジェクトを初期化しました。IBAction は既に .h ファイルに含まれているので、その部分について心配する必要はありません。
ここに私のビューがロードされました
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 700, 768, 125)];
scrollView.contentSize = CGSizeMake(1000, 125);
scrollView.backgroundColor = [UIColor darkGrayColor];
scrollView.showsHorizontalScrollIndicator = YES;
scrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
scrollView.autoresizesSubviews = NO;
[self.view addSubview:scrollView];
//////////////////////////////////////////
// //
// creating all the buttons //
// //
//////////////////////////////////////////
// strep throat
strep = [UIButton buttonWithType:UIButtonTypeRoundedRect];
strep.frame = CGRectMake(10, 10, 110, 100);
[strep setTitle:@"Strep" forState:UIControlStateNormal];
[strep setTag:DiseasesStrepThroat];
[scrollView addSubview:strep];
// the flu
flu = [UIButton buttonWithType:UIButtonTypeRoundedRect];
flu.frame = CGRectMake(130, 10, 110, 100);
[flu setTitle:@"Flu" forState:UIControlStateNormal];
[flu setTag:DiseasesFlu];
[scrollView addSubview:flu];
// chicken pox
chickenPox = [UIButton buttonWithType:UIButtonTypeRoundedRect];
chickenPox.frame = CGRectMake(250, 10, 110, 100);
[chickenPox setTitle:@"Chicken Pox" forState:UIControlStateNormal];
[chickenPox setTag:DiseasesChickenPox];
[scrollView addSubview:chickenPox];
// small pox
smallPox = [UIButton buttonWithType:UIButtonTypeRoundedRect];
smallPox.frame = CGRectMake(370, 10, 110, 100);
[smallPox setTitle:@"Small Pox" forState:UIControlStateNormal];
[smallPox setTag:DiseasesSmallPox];
[scrollView addSubview:smallPox];
// measels
measels = [UIButton buttonWithType:UIButtonTypeRoundedRect];
measels.frame = CGRectMake(490, 10, 110, 100);
[measels setTitle:@"Measels" forState:UIControlStateNormal];
[measels setTag:DiseasesMeasels];
[scrollView addSubview:measels];
// common cold
commonCold = [UIButton buttonWithType:UIButtonTypeRoundedRect];
commonCold.frame = CGRectMake(610, 10, 110, 100);
[commonCold setTitle:@"Common Cold" forState:UIControlStateNormal];
[commonCold setTag:DiseasesCommonCold];
[scrollView addSubview:commonCold];
NSArray *array = [[NSArray alloc] initWithObjects:strep, flu, chickenPox, smallPox, measels, commonCold, nil];
for(UIButton *b in array) {
b.showsTouchWhenHighlighted = YES;
}
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&//
// //
// CREATING ALL THE TARGETS //
// //
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&//
[strep addTarget:self action:@selector(showDiseasesWithTag:) forControlEvents:UIControlEventTouchUpInside];
[flu addTarget:self action:@selector(showDiseasesWithTag:) forControlEvents:UIControlEventTouchUpInside];
[chickenPox addTarget:self action:@selector(showDiseasesWithTag:) forControlEvents:UIControlEventTouchUpInside];
[smallPox addTarget:self action:@selector(showDiseasesWithTag:) forControlEvents:UIControlEventTouchUpInside];
[measels addTarget:self action:@selector(showDiseasesWithTag:) forControlEvents:UIControlEventTouchUpInside];
[commonCold addTarget:self action:@selector(showDiseasesWithTag:) forControlEvents:UIControlEventTouchUpInside];
}
そして今、私の IBAction メソッド
- (IBAction) showDiseasesWithTag:(NSInteger)senderTag {
switch (senderTag) {
case DiseasesStrepThroat:
a = [[UIAlertView alloc]
initWithTitle:@"H"
message:@"yo"
delegate:self
cancelButtonTitle:nil
otherButtonTitles:nil];
[a show];
break;
case DiseasesFlu:
[UIView animateWithDuration:1.0 animations:^ {
}completion:^(BOOL finished) {
}];
break;
case DiseasesChickenPox:
[UIView animateWithDuration:1.0 animations:^ {
}completion:^(BOOL finished) {
}];
break;
case DiseasesSmallPox:
[UIView animateWithDuration:1.0 animations:^ {
}completion:^(BOOL finished) {
}];
break;
case DiseasesMeasels:
[UIView animateWithDuration:1.0 animations:^ {
}completion:^(BOOL finished) {
}];
break;
case DiseasesCommonCold:
[UIView animateWithDuration:1.0 animations:^ {
}completion:^(BOOL finished) {
}];
break;
}
}
何かをクリアするには、すべての UIView アニメーションと完了ブロックが完了していません。私は主に最初のケースに焦点を当てています。最初のケースが 1 だったからですか?0に設定しても、何もしませんでした。
すべての実際の問題は、UIScrollView で最初の UIButton を押すと、それを押すことができますが、ボタンは IBAction メソッドに関して何もしません。全然呼んでないようです。
どんな助けでも大歓迎です。