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 8818307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:04:38+00:00 2026-06-14T05:04:38+00:00

The below Code works but not as i wish.i want that when i click

  • 0

The below Code works but not as i wish.i want that when i click UIbutton its automaically update the new value in UITableview instead of old value.Below Code works only when i press the UIbuttons and after that when i scroll the UITableview then it update the UItableview with new values.
In my application i using UITableview as Subclass of my mainclass.as image show below

enter image description here

I add Tableview in my Mainclass which is “testingViewController” like this way
In testingViewController.h

#import "Inputtableview.h"
@interface testingViewController :UIViewController<UITableViewDelegate,UITableViewDataSource> {
     Inputtableview *inputview;
     IBOutlet UITableView *inputtbl; 
}
@end

In testingViewController.m

- (void)viewDidLoad {
btn1bool=FALSE;
if (inputview == nil) {
    inputview = [[Inputtableview alloc] init];
}

[inputtbl setDataSource:inputview];
[inputtbl setDelegate:inputview];
inputview.view = inputview.tableView;
}

Now in Button action method

-(IBAction)input:(id)sender
  {
  btn1bool=TRUE;
}

my Subclass code “inputtableview.m” is show below

- (void)viewDidLoad {
 [super viewDidLoad];
listOfItems=[[NSMutableArray alloc] initWithObjects:@"Iceland",@"Greenland",@"Switzerland",
             @"Norway",@"New Zealand",@"Greece",@"Italy",@"Ireland",nil];

  array1 = [[NSMutableArray alloc] initWithObjects:@"A",@"B",@"C",@"D",@"E",@"F",@"G",@"H", nil] ;
 }

  #pragma mark -
  #pragma mark Table View datasource methods
-(NSInteger) tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section
    {
    if (btn1bool) {
        return [array1 count];
    }
else {
    return [listOfItems count];
}

[self.tableView reloadData];
   }


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

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}

NSLog(@"Row: %i", indexPath.row);
if (btn1bool) {
    NSString *cellValue = [array1 objectAtIndex:indexPath.row];
    cell.text = cellValue;
}
else {
    NSString *cellValue = [listOfItems objectAtIndex:indexPath.row];
    cell.text = cellValue;
      }
   return cell;
 }

Any help will be appriated.

  • 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-14T05:04:43+00:00Added an answer on June 14, 2026 at 5:04 am

    Just put the following code:

    [inputtbl reloadData];
    

    There are a few things you need to change in your project, but I assume this project is just for testing stuff.


    You want the date to reload after you pressed the button, so you call the method in the IBAction.

    -(IBAction)input:(id)sender
    {
        btn1bool=TRUE;
        [inputview.tableView reloadData];
    }
    

    To switch between the 2 data sources when the button is pressed you can change to this line of code: btn1bool=!btn1bool;

    (NSInteger) tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section
    {
        if (btn1bool) {
            return [array1 count];
        } else {
            return [listOfItems count];
        }
    }
    

    -(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath is correct

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

Sidebar

Related Questions

Below code works fine in Firefox, but not in IE8. It triggers mouse click
The code below does not work but meant to illustrate what I want to
The below code works in Firefox but not in Google Chrome: <!DOCTYPE html> <html>
The below code works fine on IE7 but not in Safari(5.0.5). If possible, I
the below code works perfectly in FF and CHROME but not in IE. Please
Below code not work, but it's work fine for jsf1.2. Now the framework is
The code below works well but grabs only the UIView which is VISIBLE on
the code below works fine but it takes an absolute age to run. How
Currently my code below works fine but it's a bit of overkill. In my
The code below works fine. But it seem clunky. How would you combine the

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.