views:

2670

answers:

5

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.

So, I found out the method

-(void)viewWillAppear:(BOOL)animated {

is called, HOWEVER, it doesn't have access to the tableView, like say,

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

I did stumble upon this recommendation:

"I can't seem to figure out how to make the UITableView refresh ... I did find this, which seems like the same problem I'm having,

What I did is to create a MyTableViewController* property in MyModalViewController class. Before presentModalView, I store the table view controller pointer to this property in modal view controller.

Now I have a reference to table view controller when I'm in the modal view controller. Now just use this stored table view controller to locate its tableView, then reloadData.

Feels dirty but gets work done."

If that's the answer, I'm not sure how to code it.

Thanks ahead!

  • sk

Note: I just tried this:

.h

 UITableView *tableViewPtr; 
@property (nonatomic, retain) UITableView *tableViewPtr;

.m

@synthesize tableViewPtr;

And store it in -

(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {:
 ... 
 self.tableViewPtr = tableView; 
 ...

Then try to call it from

-(void)viewWillAppear:(BOOL)animated {
 [self.tableViewPtr reloadData];

But that doesn't seem to work.

A: 

in the view will appear method (which i assume is in your controller class) call

[self.tableView reloadData];
zPesk
FavoriteViewController.m:115: error: request for member 'tableView' in something not a structure or unionI dont have a class property by that name. When I refer to tableView, I refer to the argument passed in by the tableView methods.
mr-sk
your table view controller should have access to the tableView - are you in the correct file???
zPesk
Yes - I'm in the ViewController, which contains a UIView and a UITableView.What I dont understand is HOW it would have access. The other methods in the controller, (- (UITableViewCell *)tableView:(UITableView *)tableView) have to pass in the tableView ... So ... I dont understand why I would have access to it.Like I said, I didn't make a tableView property for this class (but I could). My first post outlines my project structure (UITabController w/two UIViewControllers).
mr-sk
To help clarify: mr-sk.com/iphone/current.png -FavoriteViewController is the one Im talking about.
mr-sk
+2  A: 

Hey all,

Thanks for the help. Finally solved and here was the issue:

1) My 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
+1  A: 

You can use a UIViewController--you just need to implement the UITableViewDelegate and UITableViewDataSource protocols.

--r

+2  A: 

mr-sk: You probably need to learn a little more about how Objective-C works. When you declare the UIViewController (or a subclass) you simply implement the UITableView protocols:

@interface ViewWithTableView : UIViewController
    <UITableViewDelegate, UITableViewDataSource> {...}

Then you implement the required protocol methods inside your viewController. There are only a handful of methods you need to implement to support a tableView.

If you're using IB, define your interface like this:

@interface ViewWithTableView : UIViewController
    <UITableViewDelegate, UITableViewDataSource> {
    IBOutlet UITableView *yourTableView;
    . . .
}

and save it, then go to IB and right-click on the tableView. Click and drag bindings from both DataSource and Delegate to your viewController (likely your File's Owner.) Then click on the the viewController and type cmd-4. Select "ViewWithTableView" or whatever your called it in the Class pulldown in the Class Identity section. Save everything and it'll all work.

Note that unless you add a @property for your tableView, you won't call self because there is no accessor:

[yourTableView whatever:withWhatever];

As with any code typed off the cuff, your mileage may vary. :\

A: 

I have the following in my .h

@interface HistoryViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> {...}

But when I try to do something like this in:

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.tableView reloadData];
}

I still get the error:

"Request for member 'tableView' in something not a structure or union."

I thought implementing the UITableViewDelegate and UITableViewDataSource protocols are meant to work even when I'm using a UIViewController?

Fulvio
I'm asking this because @rwetmore said that. So I tried it and it still says that error when building.
Fulvio