私のアプリでは、サブビューとして追加されたスクロール ビューとテーブル ビューがあり、このスクロール ビューには複数のメニュー ボタン (UI ボタン) がサブビューとしてスクロール ビューに追加されています。それぞれのメニュー ボタンに応じて異なる配列を持つ table-View がタップされます。何かアイデアはありますか?
- (void)viewDidLoad
{
[super viewDidLoad];
[self PutButtoninScrollView:7];
}
-(void)PutButtoninScrollView:(int)numberOfbuttons
{
myButton1=[[UIButton alloc]init];
myButton1= [UIButton buttonWithType:UIButtonTypeCustom];
myButton1.frame=CGRectMake(5, 5, 70, 30);
[myButton1 setTitle:@"दुनिया" forState:UIControlStateNormal];
[myButton1 setTag:1];
myButton1.backgroundColor=[UIColor blackColor];
[myButton1 addTarget:self action:@selector(ListViewAction:) forControlEvents:UIControlEventTouchUpInside];
[self.myScrollView addSubview:myButton1];
myButton2=[[UIButton alloc]init];
myButton2= [UIButton buttonWithType:UIButtonTypeRoundedRect];
myButton2.frame=CGRectMake(80, 5, 70, 30);
[myButton2 setTitle:@"India" forState:UIControlStateNormal];
[myButton2 addTarget:self action:@selector(ListViewAction:) forControlEvents:UIControlEventTouchUpInside];
[self.myScrollView addSubview:myButton2];
[self.myScrollView setContentSize:CGSizeMake(160, 35)];
_myScrollView.backgroundColor=[UIColor redColor];
[self.view addSubview:self.myScrollView];
}
-(void)ListViewAction:(id)sender
{
NSLog(@"sucessful");
if ([myButton.currentTitle isEqualToString:@"दुनिया"])
{
NSLog(@"successful again 1");
}
else if ([myButton.currentTitle isEqualToString:@"भारत"])
{
NSLog(@"successful again 2");
}
}
問題は、コードを実行すると「成功」が表示されることです。つまり、ListViewAction メソッドが呼び出されますが、if ステートメントは実行されません。