How to load the same table with different NSArrays depending on the uibuttons typed?

advertisements

In my app i have a scroll-view and a table-View added as a sub-view and on this scroll view i have multiple menu buttons (UI Button) added as sub-view to my scroll-view.i want to load the table-View with different arrays depending on respective menu button is tapped.Any Ideas?

- (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");
    }
}

problem is when i execute the code "successful" is displayed. that means ListViewAction method is getting called but my if statement is never executed.


try this

[myButton1 addTarget:self action:@selector(ListViewAction:) forControlEvents:UIControlEventTouchUpInside];
[myButton2 addTarget:self action:@selector(ListViewAction:) forControlEvents:UIControlEventTouchUpInside];