Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9301795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T23:06:41+00:00 2026-06-18T23:06:41+00:00

my app has one scroll view and one tableview added as subview. on scroll

  • 0

my app has one scroll view and one tableview added as subview. on scroll view i have two buttons. i want to load two separate arrays in my tableview on pressing these buttons.but for some reason it just doesnt happen. can anyone please help me what i am doing wrong?

- (void)viewDidLoad
{
    [super viewDidLoad];
worldArray=[[NSMutableArray alloc]initWithObjects:@"1",@"2",@"3",nil];
IndiaArray=[[NSMutableArray alloc]initWithObjects:@"abc",@"pqr",@"xyz", nil];
 [self PutButtoninScrollView:2];
}

-(void)PutButtoninScrollView:(int)numberOfbuttons
{
    myButton1=[[UIButton alloc]init];
    myButton1= [UIButton buttonWithType:UIButtonTypeCustom];
    myButton1.frame=CGRectMake(5, 5, 70, 30);
    [myButton1 setTitle:@"World" 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
{

    if ([[sender currentTitle] isEqualToString:@"World"])
    {
        NSLog(@"successful ");            
        [tempArray addObject: worldArray];
    }
    else if ([[sender currentTitle] isEqualToString:@"India"])
    {
         NSLog(@"successful again");
        [tempArray addObject: IndiaArray];
    }
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [tempArray count];
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier=@"cell";
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if(cell==nil)
    {
        cell=[[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier]autorelease];
        cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
    }

    cell.textLabel.text=[tempArray objectAtIndex:indexPath.row];

    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    DetailViewController *detailViewCont=[[DetailViewController alloc]initWithNibName:@"DetailViewController" bundle:nil];
    [self presentViewController:detailViewCont animated:YES completion:nil];

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T23:06:42+00:00Added an answer on June 18, 2026 at 11:06 pm

    Try using below code

    in .h

    NSMutableArray *tempArray;
    NSMutableArray *worldArray;
    NSMutableArray *IndiaArray;
    

    in .m

      - (void)viewDidLoad
     {
       [super viewDidLoad];
    
       tempArray = [NSMutableArray alloc]init];
       worldArray=[[NSMutableArray alloc]initWithObjects:@"1",@"2",@"3",nil];
       IndiaArray=[[NSMutableArray alloc]initWithObjects:@"abc",@"pqr",@"xyz", nil];
       [self PutButtoninScrollView:2];
      }
    
    
    
    -(void)ListViewAction:(id)sender
     {
    
         if ([[sender currentTitle] isEqualToString:@"World"])
          {
            [tempArray removeAllObjects];
            [tempArray addObjectsFromArray:worldArray];
    
          }
        else if ([[sender currentTitle] isEqualToString:@"India"])
         {
            [tempArray removeAllObjects];
            [tempArray addObjectsFromArray: IndiaArray];
         }
    
      [yourTableView reloadData];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, I want to have an app with only one view that has an
I have created an app wherein I have a large scroll view (two page
I have applied scroll view to the entire layout and that layout has one
Iam making an app which has one index.php file. I also have these other
Okay, when my app starts it has two tabs, and one action in the
In my iOS app have a UITableView which contains a custom subview in one
I have an Android app using PhoneGap 1.6 and Sencha Touch 1.1.1. One view
I have a C#.NET MVC3 web app. I have a View that has a
Hi i made an application which has 2 views one paging scroll view which
I have an app with one main TabBarController containing two tabs that control two

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.