Reputation: 4209
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;
}
Upvotes: 17
Views: 7605
Reputation: 4575
When initialising the view just do the following:
CustomTableViewController *viewController = [[CustomTableViewController alloc] initWithStyle:UITableViewStyleGrouped];
[self.navigationController pushViewController:viewController animated:YES];
[viewController release];
Rather than just init. This solves it for me.
Upvotes: 4
Reputation: 111
You need to specify the Nib name when you create the class or else it will not look for the default nib named the same as your class. For some reason Apple decided to include its own table view as a default.
For example if your class name is "Settings":
settingsController = [[Settings alloc] initWithNibName:@"Settings" bundle: nil];
Upvotes: 2
Reputation: 91
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.
Upvotes: 9
Reputation: 2741
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.
Upvotes: 13
Reputation: 4209
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;
}
Upvotes: 8
Reputation: 9507
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.
Upvotes: 0