UIToolBar with UITableView - TableView is not refreshing when loaded
Hello,
The UIToolBar has two views, a UIView w/UITextViews and a UIView w/UITableView.
The UITableView that gets called via a UIToolBar. The first time the UITableView loads, it hits the DB and gets the info. I "tab" back to the UIView w/UITextViews select some data, and then "tab" back to the UITableView, but none of the delegate methods get called, like viewDidLoad or initWithNibName or anything, thus the data in the table is stale.
How can I either
1) Kill the view so its forced to re instantiate and thus reload.
2) Force a reload? But even viewDidLoad isn't getting called so ...
The UIToolBar has two views, a UIView w/UITextViews and a UIView w/UITableView.
The UITableView that gets called via a UIToolBar. The first time the UITableView loads, it hits the DB and gets the info. I "tab" back to the UIView w/UITextViews select some data, and then "tab" back to the UITableView, but none of the delegate methods get called, like viewDidLoad or initWithNibName or anything, thus the data in the table is stale.
How can I either
1) Kill the view so its forced to re instantiate and thus reload.
2) Force a reload? But even viewDidLoad isn't getting called so ...
Ah - yeah, but my main question is - where would I put that call? Since, viewDidLoad() isn't getting called, or any function for that matter, where would I put it?
It seems like once the controller is loaded, when I "tab" back to the view, it never actually runs code, it just loads a cached version of the table ...
Writing code is not only about writing instructions to a machine / computer, but also about writing something that could be read, understood, and maintained by others. That's why, I like Cocoa.
viewWillAppear: or using notifications might be your solution.
viewWillAppear:animated works, BUT, I dont have access to the tableView, since its not passed in as an argument. So, how do I force it to be redrawn if I cannot call [tableView reloadData]?
Ideally, I THINK I want:
-(void)viewWillAppearBOOL)animated {
[tableView reloadData];
}
But, I dont have access to the tableView, like I would in say:
Writing code is not only about writing instructions to a machine / computer, but also about writing something that could be read, understood, and maintained by others. That's why, I like Cocoa.
Thanks for the help. Finally solved and here was the issue:
1) By controller was extending UIViewController, NOT UITableViewController.
Once I extended the correct class, and then wired it correctly via File's Owner and IB, it worked. Now in viewWillAppear I can call self.tableView reloadData.
Thanks for the help. Finally solved and here was the issue:
1) By controller was extending UIViewController, NOT UITableViewController.
Once I extended the correct class, and then wired it correctly via File's Owner and IB, it worked. Now in viewWillAppear I can call self.tableView reloadData.
Won't ever make that mistake again!
Thanks all -
sk
Hello:
I am not using IB to create my UITableViewController - just creating the class and having it conform to <UITableViewDelegate, UITableViewDataSource>. I can't get viewWillAppear to fire a
Code:
[[self tableview] reloadData];
Do I have to rework my code to get an outlet to the table for this to work?
Thanks in advance.
I'm having the same problem. I have a segmented control in a toolbar above a table and would like to refresh the visible table cells when the segment action is called. [self.tableView reloadData] does nothing because self.tableview is returning nil.
I believe the delegate and dataSource are hooked up correctly in IB. The table updates the cells if they are scrolled off and regenerated but not when they are visible.
Do I have to rework my code to get an outlet to the table for this to work?
Depends on how you create the UIViewController subclass, if you create its view as a subview of a view of a root view controller, the viewWillAppear: will not get called.
Writing code is not only about writing instructions to a machine / computer, but also about writing something that could be read, understood, and maintained by others. That's why, I like Cocoa.
I'm having the same problem. I have a segmented control in a toolbar above a table and would like to refresh the visible table cells when the segment action is called. [self.tableView reloadData] does nothing because self.tableview is returning nil.
I believe the delegate and dataSource are hooked up correctly in IB. The table updates the cells if they are scrolled off and regenerated but not when they are visible.
Any help would be appreciated.
Have you connected the tableView on the IB, with the outlet on the view controller ?
Writing code is not only about writing instructions to a machine / computer, but also about writing something that could be read, understood, and maintained by others. That's why, I like Cocoa.
Writing code is not only about writing instructions to a machine / computer, but also about writing something that could be read, understood, and maintained by others. That's why, I like Cocoa.
I just can't get this tableview to reload. I'm finding it hard to believe that I have to have a XIB file with an outlet defined just to get the table to reload.
Is that viewController really is a UITableViewController instance ?
For SecondLevelViewController, it seems to me you're implementing your own table view controller, so I don't think there's any need to use XIB, just assign the delegate and data source of the table view to the SubscriptionDetailController.
Writing code is not only about writing instructions to a machine / computer, but also about writing something that could be read, understood, and maintained by others. That's why, I like Cocoa.
Is that viewController really is a UITableViewController instance ?
For SecondLevelViewController, it seems to me you're implementing your own table view controller, so I don't think there's any need to use XIB, just assign the delegate and data source of the table view to the SubscriptionDetailController.
My SecondLevelViewController is defined like this:
The above code is just not getting called. Looks like the way to go based on the documentation. Why isn't this method firing??
Any help is much appreciated. Thanks.
Writing code is not only about writing instructions to a machine / computer, but also about writing something that could be read, understood, and maintained by others. That's why, I like Cocoa.
-(void)tableView: (UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
//This method gets called when a user taps a row in the table.
{
NSUInteger row = [indexPath row];
//Get the corresponding controller for the current row selected.
SecondLevelViewController *nextController = [self.controllers objectAtIndex:row];
//Since the navigation controller is maintained by the application delegate, we use the shared
//UIApplication instance to grab a reference to that delegate.
myAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
//We use the delegate's navController outlet, which points to our applications's navigation controller,
//to push the next controller, the one we pulled from our array, on to the navigation controller's stack.
[delegate.navController pushViewController:nextController animated:YES];
}
And finally, I have the following code in my SubscriptionDetailController.m:
// There's no need to declare those other protocols
@interface SubscriptionDetailController : SecondLevelViewController <UINavigationControllerDelegate>
Writing code is not only about writing instructions to a machine / computer, but also about writing something that could be read, understood, and maintained by others. That's why, I like Cocoa.
// There's no need to declare those other protocols
@interface SubscriptionDetailController : SecondLevelViewController <UINavigationControllerDelegate>
I thought you had to assign the UITableViewDelegate, UITableViewDataSource, in order to have a view create a table automatically without having to define an outlet to a XIB. No?
I thought you had to assign the UITableViewDelegate, UITableViewDataSource, in order to have a view create a table automatically without having to define an outlet to a XIB. No?
That's not an assignment, but it's a way to declare that a class is adopting a formal protocol, in other words it's conforming to a protocol.
UITableViewController already conforms to those protocols.
Quote:
Originally Posted by hstaniloff
Hmmm.... Ok. [Trying to understand this assignment.] Should I include this assignment in the ViewDidLoad method? Or where? Thanks!
Preferably when you allocate the SubscriptionDetailViewController instance.
Writing code is not only about writing instructions to a machine / computer, but also about writing something that could be read, understood, and maintained by others. That's why, I like Cocoa.
I thought you had to assign the UITableViewDelegate, UITableViewDataSource, in order to have a view create a table automatically without having to define an outlet to a XIB. No?
Just to clarify, a view will only create the table automatically if it's an instance of (or an instance of a subclass of) UITableViewController. If either of those are true, then you can just reference it via self.tableView.
If those things are not true, then you have to either create the tableview yourself with alloc/init, or by loading it from a nib. If you create it yourself with alloc/init, you should probably assign it to a retaining property on the instance so that you can access it later. If you load it from a nib then you have to connect the tableview in the nib to your class with an IBOutlet.
Adding the delegate/datasource protocols to a class does not create the actual table view. It just says your class can respond to those protocols.
Writing code is not only about writing instructions to a machine / computer, but also about writing something that could be read, understood, and maintained by others. That's why, I like Cocoa.