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

  • Home
  • SEARCH
  • 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 6471895
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:16:41+00:00 2026-05-25T06:16:41+00:00

So I know that if you guys don’t like my question you are going

  • 0

So I know that if you guys don’t like my question you are going to vote me down and reduce my reputation 🙁 but I need to learn and can’t find a answer so here I’m risking my reputation again.
Now to the point. All I’m trying to do is one View with two buttons and a table view under the buttons, this table view needs to display a different array depending witch button was click, in other words all I want it to do is if I click button1 display array1, if I click button2 display array2, simple! but I can’t get it to work.
Here is a sample of my code:

- (void)viewDidLoad
{

array1 = [[NSArray arrayWithObjects:
               @"A",
               @"B",
               @"c",
               @"D", nil] retain];

array2 = [[NSArray arrayWithObjects:
               @"1",
               @"2",
               @"3",
               @"4", nil] retain];
}

- (IBAction)btnPeriodicos:(id)sender {
displayArray = 1;
}

- (IBAction)btnRadios:(id)sender {
displayArray = 2;
}


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

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
 if (displayArray == 1) {
 return [array1 count];
 }
 if (displayArray == 2) {
 return [array2 count];
 }
 [self.tableView reloadData];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath    *)indexPath
{
static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}

// Configure the cell.
cell.textLabel.textAlignment = UITextAlignmentCenter;
cell.textLabel.textColor = [UIColor blackColor];
if (menuNumberInt == 1) {
    cell.textLabel.text = [[periodicoArray objectAtIndex:indexPath.row] retain];
}
if (menuNumberInt == 2) {
    cell.textLabel.text = [[radioArray objectAtIndex:indexPath.row] retain];
}

return cell; 
 }

If I put instead of the if else statements either [array1 count] for the numberOfRowsInSection and the cell.textLabel.text = [[periodicoArray objectAtIndex:indexPath.row] retain]; the app loads with the table fill with that array so I guess the table works, but how can I make my buttons change the table cells?
any help is greatly appreciated.
Thanks

  • 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-05-25T06:16:42+00:00Added an answer on May 25, 2026 at 6:16 am

    You can have an iVar variable for NSArray *currentArray. In viewDidLoad you can define your two arrays (as you currently do) but then assign currentArray to array1.

    Then, change all the tableView callbacks to operate off of currentArray and get rid of the if (displayArray == x) checks.

    in the (IBAction) button handlers, assign currentArray to the appropriate array and call [tableView reloadData]. that will clear the table and trigger all the tableView callbacks to happen again. since the currentArray changed, all the callback will pull data from the appropriate array.

    Hope that helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know that this is a simple question for PHP guys but I don't
Hi guys i am going to make a android game. i wanna know that
I know that this sort of question has been asked here before, but still
Hope you guys don't mind me asking this question, but I find myself at
Now i know that this one is actually not a very technical question but
I know that Phonegap has an event for back button, but it's only available
I know that Java have its own garbage collection, but sometimes I want to
Hi Guys I don't quite understand the following tutorial question: write a ADT sorted
I know that PHP doesn't yet have native Enumerations. But I have become accustomed
I don't know if you are able to do this, but... Is there anyway

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.