views:

373

answers:

4

For some reason, [self.tableView reloadData]; just wont work. In my .h file I have:

@interface SearchOptions : UIViewController <UINavigationBarDelegate, UITableViewDelegate, UITableViewDataSource> 
{
    IBOutlet UITableView *myTableView;
     .....
}

I've tried:

[self.tableView reloadData];

and

[self.myTableView reloadData];

Any ideas what might be happening?

+2  A: 

Are you sure it's non-nil? That is, that your outlet is properly connected?

Is the property tableView synthesized to the ivar myTableView? (You don't include that code in your question.)

Sixten Otto
How would you synthesize the tableView property to the ivar myTableView?Thanks for the help!
Jonah
Do you mean: @property (nonatomic, retain) UITableView *myTableView;
Jonah
In @Implementation file (.m)@synthesize myTableView;
Jordan
You don't need to synthesize it, so that won’t be the problem.
Chris Suter
Yes, it was synthesized.
Jonah
+1  A: 

Your outlet isn't connected in IB.

Jordan
Actually, it is connected. But it's acting like it isn't.
Jonah
+1  A: 

Check that you’ve correctly bound your outlet in Interface Builder (check myTableView is not nil). If that’s not it, are you getting the initial data in your table view? If not, then it probably means you haven’t set your SearchOptions instance as the data source for your table—check this in Interface Builder and stick some break points on the data source methods.

Chris Suter
I've set: myTableView.delegate = self; and myTableView.dataSource = self; ...nothing. The outlets and class are set in IB as well. The table displays just fine in a grouped style (set in IB). It's always the little unexpected problems that get you!
Jonah
Should I be allocating or initializing myTableView somehow?
Jonah
If I add myTableView.dataSource = nil; the table is blank. So I guess it isn't nil.
Jonah
+1  A: 

I solved it! The problem was that because of other reasons, I wasn't able to reuse my cells and this was my code:

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

NSString *kCustomCellID = [NSString stringWithFormat:@"MyCellID%d", indexPath];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kCustomCellID];
if (cell == nil) 
{
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kCustomCellID] autorelease];
    cell.selectionStyle = UITableViewCellSelectionStyleBlue;

 if (selectOrDeselectInteger == 1) {
  cell.accessoryType = UITableViewCellAccessoryCheckmark; 
 }
 if (selectOrDeselectInteger == 2) {
  cell.accessoryType = UITableViewCellAccessoryNone;
 }
}

I just had to add this afterwards:

    if (cell != nil) 
{
 if (selectOrDeselectInteger == 1) {
  cell.accessoryType = UITableViewCellAccessoryCheckmark; 
 }
 if (selectOrDeselectInteger == 2) {
  cell.accessoryType = UITableViewCellAccessoryNone;   
 }
}

Thanks everyone for the help. Sorry this code wasn't in the question.

Jonah