views:

957

answers:

4

I've created a table view in an iPhone app using Interface Builder (IB). My table style is set to Grouped, and displays that way in IB. However, whenever I build and run, it shows up as a Plain style in the simulator.

I have another view set to Grouped and don't experience this problem. Has anyone run into this problem before?

The rest of the view is not created programmatically, so I'd like to avoid doing that for this view. There must be something I'm missing.

The only tableView method I'm doing much of anything in is the cell handler method where I'm incorporating a text box into select fields:

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

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
}

if (indexPath.section == 0) {
 if (indexPath.row == 0) {
  cell.textLabel.text = @"Title";

  UITextField *listTitleTextField = [ [ UITextField alloc ] initWithFrame: CGRectMake(150, 10, 145, 38) ];
  listTitleTextField.adjustsFontSizeToFitWidth = YES;
  listTitleTextField.textColor = [UIColor blackColor];
  listTitleTextField.font = [UIFont systemFontOfSize:17.0];
  listTitleTextField.placeholder = @"Your Title";
  listTitleTextField.backgroundColor = [UIColor whiteColor];
  listTitleTextField.autocorrectionType = UITextAutocorrectionTypeNo;        // no auto correction support
  listTitleTextField.autocapitalizationType = UITextAutocapitalizationTypeNone; // no auto capitalization support
  listTitleTextField.textAlignment = UITextAlignmentRight;
  listTitleTextField.keyboardType = UIKeyboardTypeDefault; // use the default type input method (entire keyboard)
  listTitleTextField.returnKeyType = UIReturnKeyDone;
  listTitleTextField.tag = 0;
  listTitleTextField.delegate = self;

  listTitleTextField.clearButtonMode = UITextFieldViewModeUnlessEditing; // no clear 'x' button to the right
  if (self.wishList.listTitle == nil || [self.wishList.listTitle length] == 0) {
   listTitleTextField.text = @"";
  }
  else {
   listTitleTextField.text = self.wishList.listTitle;
  }
  [listTitleTextField setEnabled: YES ];
  [cell addSubview: listTitleTextField ];
  [listTitleTextField release];
 }
 else if (indexPath.row == 1) {
  cell.detailTextLabel.text = @"Pick an Icon";
  cell.textLabel.text = @"List Icon";
 }
}
else {
 cell.textLabel.text = @"Add Wish";
}

return cell;

}

A: 

Does the table view respond to events and get populated with data as you'd expect? - it sounds like the outlets are not connected properly to me. I'd double check the datasource and delegate connections from the tableview to the controller. May be worth deleting the tableview from IB and re-adding it and re-connecting it as well. I've seen IB act a little finicky in the odd case.

paulthenerd
Deleted it and created a new table view. Then attached data source and delegate to the file owner. Also attached the view in file owner to the table. Issue reamins the same.
Tony Lenzi
+1  A: 

Still not sure why the "grouped" style setting is not taking effect from the Interface Builder. However, you can manually set it before the view is created here:

- (id)initWithStyle:(UITableViewStyle)style {
    // Override initWithStyle: if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
    style = UITableViewStyleGrouped;
    if (self = [super initWithStyle:style]) {
    }
    return self;
}
Tony Lenzi
+1  A: 

We had this and it stumped us for about an hour. Finally we found that we had failed to set the NIB Name property of the view controller inside the navigation controller (inside the tab bar controller, in our main XIB!). Without that set, all the changes we made to the XIB file of our table view were completely ignored. Yet the code worked fine otherwise, and there was very little to point us to our mistake.

I bet something similar is going on in your case. Make sure your XIB (where you set the table style) is actually being used.

Joe Strout
+3  A: 

What is your controller's base class? I had the same problem, until I switched my controller from subclassing a UITableViewController to just a standard UIViewController. It would seem if you're using a UITableViewController, it has its own built-in UITableView and ignores the one you specify in IB.

shaug
That worked in my case! Thank you!
Sebastian Wramba
Helped me too this - thanks!
Matt Facer