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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:48:18+00:00 2026-05-26T01:48:18+00:00

Hi I have a tab tab controller and my first tab includes a view

  • 0

Hi I have a tab tab controller and my first tab includes a view with:

  • 3 text fields
  • a submit button
  • a tableView

Once I fill in the text fields I click submit and it adds the information to my managedObjectContext which is an sqlite database (CoreData).

As soon as I click submit I want the tableView to reload to include the added object. Currently my tableView will display the data in the database but it will only add the new row when I stop and re-run the simulator

This is the code for when the add button is tapped, it is here that I can’t get the reload tableView working because it says tableView is an undeclared identifier, what have i missed?

-(IBAction)addButtonTapped:(id)sender {
NSLog (@"Add Button Tapped");
NSLog(@"Adding %@ units of item code %@ at $%@ each",quantityTextField.text,productTextField.text,priceTextField.text);


Products_MarketAppDelegate* delegate = [[UIApplication sharedApplication] delegate];
NSManagedObjectContext* managedObjectContext = delegate.managedObjectContext;
NSManagedObject* newProduct;
newProduct = [NSEntityDescription insertNewObjectForEntityForName:@"Product" inManagedObjectContext:managedObjectContext];

[newProduct setValue:productTextField.text forKey:@"itemCode"];
[newProduct setValue:quantityTextField.text forKey:@"quantity"];
[newProduct setValue:priceTextField.text forKey:@"price"];

if ([managedObjectContext hasChanges]) 
    NSLog(@"Managed Object Changed");

NSError* error;
[managedObjectContext save:&error];

// Insert Reload Table Code Here
// ** I have tried the following and it gives an error "Use of undeclared identifier 'tableView'"
//[tableView reloadData];
//[self.tableView reloadData];

}

As you can see below I have added the UITableViewDelegate & UITableViewDataSource in the header file. I have also hooked up the tableview in IB so that the delegate and datasource connections are linked to file’s owner.

#import <UIKit/UIKit.h>
#import <CoreData/CoreData.h>


@interface FirstViewController : UIViewController
<UIApplicationDelegate, UITableViewDataSource,UITableViewDelegate,NSFetchedResultsControllerDelegate>

{
IBOutlet UITextField *productTextField;
IBOutlet UITextField *quantityTextField;
IBOutlet UITextField *priceTextField;

NSMutableArray *items;
NSFetchedResultsController *fetchedResultsController;
}

@property (nonatomic, retain) NSMutableArray *items;
@property (nonatomic, retain) NSFetchedResultsController *fetchedResultsController;

-(IBAction)addButtonTapped:(id)sender;

@end

This is the code to fill the tableView which works correctly

#pragma mark TableView
-(NSInteger)numberOfSectionsInTableView: (UITableView *)tableView {
return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{
id <NSFetchedResultsSectionInfo> sectionInfo = [[fetchedResultsController sections] objectAtIndex:section];
return [sectionInfo numberOfObjects];
}

- (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
Product* productItem =[fetchedResultsController objectAtIndexPath:indexPath];
cell.textLabel.text = [NSString stringWithFormat:@"%@ x %@ @ $%@",productItem.quantity,productItem.itemCode,productItem.price];

return cell;  
}

I have searched for answers on this site and on others but I must be doing something different and the solutions aren’t helping me

  • 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-26T01:48:19+00:00Added an answer on May 26, 2026 at 1:48 am

    Your UIViewController does not currently have an instance variable pointing to your tableview. Set one up:

    @property (nonatomic, retain) IBOutlet UITableView *myTableView;
    

    Remember to synthesize this in your .m

    @synthesize myTableView;
    

    Then in your code you can call

    [self.myTableView reloadData];
    

    You might have got confused by looking at code examples that use a UITableViewController instead of a UIViewController. The UITableViewController already has an instance variable called tableView, so your subclass wouldn’t need it’s own tableView instance variable declared. But you’re using a UIViewController, so you must declare a tableView instance variable.

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

Sidebar

Related Questions

I am creating my first tab controller app. I have 2 tabs with 2
I have created tab bar programmatically in the view controller. In my application, Initially
Description I have a Tab Bar Controller with a navigation controller tab. The first
i have a tab bar controller as a root controller. In its first tab
I have a root view controller which has few buttons. On click of these
I have 2 tab bar items. The first tab have a navigation controller(3 views)
I have 2 views controlled by a tab bar view controller created by the
I have a tab bar controller and in both tab bar items i have
I have a Tab Bar Controller created in Interface Builder Within the Tab Bar
Let's have an example. In application I have a tab bar controller. Tab bar

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.