Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 05-31-2009, 09:44 PM   #1 (permalink)
.38 special tucked
 
Join Date: Apr 2009
Location: Brooklyn, NY
Posts: 133
Default 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 ...

Any ideas?

- sk
mr-sk is offline   Reply With Quote
Old 06-01-2009, 02:19 AM   #2 (permalink)
Registered Member
 
Join Date: Jan 2009
Location: India
Posts: 107
Default

Quote:
Originally Posted by mr-sk View Post
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 ...

Any ideas?

- sk
Have tried reload option of table?

[tableView reloadData];
Jindal is offline   Reply With Quote
Old 06-01-2009, 09:41 AM   #3 (permalink)
.38 special tucked
 
Join Date: Apr 2009
Location: Brooklyn, NY
Posts: 133
Default

Quote:
Originally Posted by Jindal View Post
Have tried reload option of table?

[tableView reloadData];
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 ...

I dont know.

Thanks though -

- sk
mr-sk is offline   Reply With Quote
Old 06-01-2009, 10:42 AM   #4 (permalink)
Registered Member
 
mnemonic_fx's Avatar
 
Join Date: Jun 2008
Posts: 419
Default

viewWillAppear: or using notifications might be your solution.
__________________
Visit Me

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.
mnemonic_fx is offline   Reply With Quote
Old 06-01-2009, 09:19 PM   #5 (permalink)
.38 special tucked
 
Join Date: Apr 2009
Location: Brooklyn, NY
Posts: 133
Default

Quote:
Originally Posted by mnemonic_fx View Post
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:

- (UITableViewCell *)tableViewUITableView *)tableView .....

Thanks

- sk
mr-sk is offline   Reply With Quote
Old 06-02-2009, 06:41 AM   #6 (permalink)
Registered Member
 
mnemonic_fx's Avatar
 
Join Date: Jun 2008
Posts: 419
Default

You need to have access to the UITableView instance.

You can retain the instance inside the view controller that's calling viewWillAppear:
__________________
Visit Me

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.
mnemonic_fx is offline   Reply With Quote
Old 06-02-2009, 08:43 AM   #7 (permalink)
Registered Member
 
Join Date: Jan 2009
Location: India
Posts: 107
Default

Quote:
Originally Posted by mnemonic_fx View Post
You need to have access to the UITableView instance.

You can retain the instance inside the view controller that's calling viewWillAppear:
Hey why don't you give reload data event on tab click. So on every click it will fire that event.
Jindal is offline   Reply With Quote
Old 06-02-2009, 08:46 PM   #8 (permalink)
.38 special tucked
 
Join Date: Apr 2009
Location: Brooklyn, NY
Posts: 133
Default Solved

Hey all,

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
mr-sk is offline   Reply With Quote
Old 06-18-2009, 03:07 PM   #9 (permalink)
Registered Member
 
Join Date: Apr 2009
Location: Setauket, NY
Posts: 133
Question similiar issue...

Quote:
Originally Posted by mr-sk View Post
Hey all,

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.
hstaniloff is offline   Reply With Quote
Old 06-20-2009, 12:25 PM   #10 (permalink)
Physician developer
 
StatCoder's Avatar
 
Join Date: Aug 2008
Location: Austin, TX
Posts: 221
Default

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.
StatCoder is offline   Reply With Quote
Old 06-20-2009, 12:38 PM   #11 (permalink)
Registered Member
 
mnemonic_fx's Avatar
 
Join Date: Jun 2008
Posts: 419
Default

Quote:
Originally Posted by hstaniloff View Post
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.
__________________
Visit Me

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.
mnemonic_fx is offline   Reply With Quote
Old 06-20-2009, 12:39 PM   #12 (permalink)
Registered Member
 
mnemonic_fx's Avatar
 
Join Date: Jun 2008
Posts: 419
Default

Quote:
Originally Posted by StatCoder View Post
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 ?
__________________
Visit Me

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.
mnemonic_fx is offline   Reply With Quote
Old 06-23-2009, 05:16 PM   #13 (permalink)
Registered Member
 
Join Date: Apr 2009
Location: Setauket, NY
Posts: 133
Question

Quote:
Originally Posted by mnemonic_fx View Post
Have you connected the tableView on the IB, with the outlet on the view controller ?
I have not implemented my table via IB. But it looks like I have to based on the thread, no?
hstaniloff is offline   Reply With Quote
Old 06-24-2009, 04:13 PM   #14 (permalink)
Registered Member
 
mnemonic_fx's Avatar
 
Join Date: Jun 2008
Posts: 419
Default

I'm not sure how did you implement it.

If the self.tableView is nil then it's not created / allocated yet.

But, in that case, the delegates shouldn't work, when you scroll it.

What do you mean by "thread" ?
__________________
Visit Me

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.
mnemonic_fx is offline   Reply With Quote
Old 06-24-2009, 04:25 PM   #15 (permalink)
Registered Member
 
Join Date: Apr 2009
Location: Setauket, NY
Posts: 133
Question

Quote:
Originally Posted by mnemonic_fx View Post
I'm not sure how did you implement it.

If the self.tableView is nil then it's not created / allocated yet.

But, in that case, the delegates shouldn't work, when you scroll it.

What do you mean by "thread" ?
Here is what my interface declaration looks:
Code:
@interface SubscriptionDetailController : SecondLevelViewController <UITableViewDelegate, UITableViewDataSource, UINavigationControllerDelegate>
I added UINavigationControllerDelegate protocol and have this method defined in my .m file:
Code:
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
	if ([viewController isKindOfClass:[UITableViewController class]])
	{
		UITableViewController *controller = (UITableViewController*)viewController;
		[controller.tableView reloadData];
	}
}
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.
hstaniloff is offline   Reply With Quote
Old 06-24-2009, 08:42 PM   #16 (permalink)
Registered Member
 
mnemonic_fx's Avatar
 
Join Date: Jun 2008
Posts: 419
Default

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.
__________________
Visit Me

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.
mnemonic_fx is offline   Reply With Quote
Old 07-07-2009, 09:37 AM   #17 (permalink)
Registered Member
 
Join Date: Apr 2009
Location: Setauket, NY
Posts: 133
Default

Quote:
Originally Posted by mnemonic_fx View Post
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:
Code:
@interface SecondLevelViewController : UITableViewController {
	UIImage *rowImage;
}
Then, my SubscriptionDetailController is implemented like so:
Code:
@interface SubscriptionDetailController : SecondLevelViewController <UITableViewDelegate, UITableViewDataSource, UINavigationControllerDelegate>
This code is in the implementation file of SubscriptionDetailController:
Code:
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
	if ([viewController isKindOfClass:[UITableViewController class]])
	{
		UITableViewController *controller = (UITableViewController *)viewController;
		[controller.tableView reloadData];
	}
}
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.
hstaniloff is offline   Reply With Quote
Old 07-07-2009, 09:57 AM   #18 (permalink)
Registered Member
 
mnemonic_fx's Avatar
 
Join Date: Jun 2008
Posts: 419
Default

Have you assigned the SubscriptionDetailController instance to the delegate of UINavigationController instance?
__________________
Visit Me

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.
mnemonic_fx is offline   Reply With Quote
Old 07-07-2009, 10:59 AM   #19 (permalink)
Registered Member
 
Join Date: Apr 2009
Location: Setauket, NY
Posts: 133
Default

Quote:
Originally Posted by mnemonic_fx View Post
Have you assigned the SubscriptionDetailController instance to the delegate of UINavigationController instance?
Please take a look at the following code segments from the various implementation files.
Here is what I am doing in my AppDelegate:
Code:
@implementation GPSJEDIAppDelegate

@synthesize window;
@synthesize navController;


- (void)applicationDidFinishLaunching:(UIApplication *)application {    

	[window addSubview: navController.view];
	[window makeKeyAndVisible];
}
My first view controller has this code:
Code:
-(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:
Code:
-(void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
{
	if (myCardController == nil)
		myCardController = [[myCardController alloc] initWithNibName:@"myCard" bundle:nil];
	
	
	NSUInteger currentRow = [indexPath row];
	
	myCardController.title = @"My Card";
	myCardController.subscription_index = currentRow;
		
	myAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
	[appDelegate.navController pushViewController:myCardController animated:YES];	
}
So I do believe I am assigning the navcontroller correctly. No?
Thanks.
hstaniloff is offline   Reply With Quote
Old 07-07-2009, 11:13 AM   #20 (permalink)
Registered Member
 
mnemonic_fx's Avatar
 
Join Date: Jun 2008
Posts: 419
Default

Okay first,

Code:
// There's no need to declare those other protocols
@interface SubscriptionDetailController : SecondLevelViewController <UINavigationControllerDelegate>
If you want, this:
Code:
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
To be called, you need to assign the delegate:
Code:
...

[[myAppDelegate navController] setDelegate:subscriptionDetailViewController];

...
__________________
Visit Me

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.
mnemonic_fx is offline   Reply With Quote
Old 07-07-2009, 11:53 AM   #21 (permalink)
Registered Member
 
Join Date: Apr 2009
Location: Setauket, NY
Posts: 133
Default

Quote:
Originally Posted by mnemonic_fx View Post
Okay first,

Code:
// 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?
Quote:
If you want, this:
Code:
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
To be called, you need to assign the delegate:
Code:
[[myAppDelegate navController] setDelegate:subscriptionDetailViewController];
Hmmm.... Ok. [Trying to understand this assignment.] Should I include this assignment in the ViewDidLoad method? Or where? Thanks!
hstaniloff is offline   Reply With Quote
Old 07-07-2009, 01:58 PM   #22 (permalink)
Registered Member
 
mnemonic_fx's Avatar
 
Join Date: Jun 2008
Posts: 419
Default

Quote:
Originally Posted by hstaniloff View Post
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 View Post
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.
__________________
Visit Me

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.
mnemonic_fx is offline   Reply With Quote
Old 07-07-2009, 03:08 PM   #23 (permalink)
jsd
at this moment
 
Join Date: Mar 2009
Location: San Francisco, CA
Posts: 900
Default

Quote:
Originally Posted by hstaniloff View Post
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.
jsd is offline   Reply With Quote
Old 07-07-2009, 04:05 PM   #24 (permalink)
Registered Member
 
Join Date: Apr 2009
Location: Setauket, NY
Posts: 133
Default

Quote:
Originally Posted by mnemonic_fx View Post
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.

Preferably when you allocate the SubscriptionDetailViewController instance.
I removed the UITableViewDelegate,UITableViewSource protocol assignments on my SubscriptionDetailController class definition as follows:
Code:
@interface SubscriptionDetailController : SecondLevelViewController <UINavigationControllerDelegate>
The code works fine with this modification.

I have code in my first view controller's implementation file as follows:
Code:
SubscriptionDetailController *nextViewCtrlr = [[SubscriptionDetailController alloc] initWithStyle:UITableViewStylePlain];
PgmAppDelegate *myAppDelegate = [[UIApplication sharedApplication] delegate];

[[myAppDelegate navController] setDelegate:nextViewCtrlr];
With this modification, my code crashes when I pop back to this SubsriptionDetailController. I tried setting a break point in the
Code:
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
but I get the dreaded obj_msg. Any ideas?
hstaniloff is offline   Reply With Quote
Old 07-07-2009, 04:42 PM   #25 (permalink)
Registered Member
 
mnemonic_fx's Avatar
 
Join Date: Jun 2008
Posts: 419
Default

What's the dreaded message ?
__________________
Visit Me

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.
mnemonic_fx is offline   Reply With Quote
Reply

Bookmarks

Tags
refresh, uitableview, uitoolbar

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 276
20 members and 256 guests
ADY, Bertrand21, Dani77, HemiMG, iDifferent, IphoneSdk, jakerocheleau, JasonR, jimbo, macquitzon216, MACralik, mer10, NSeven, prchn4christ, Rudy, silverwiz, spiderguy84, Sunny46
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,885
Threads: 89,230
Posts: 380,767
Top Poster: BrianSlick (7,129)
Welcome to our newest member, bookesp
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 03:00 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0