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;
}
Starting in iOS7, there is additional space at the top of my UITableView 's which have a style UITableViewStyleGrouped . The tableview starts at the first arrow, there are 35 pixels of unexplained padding, then the green header is a UIView returned by viewForHeaderInSection (where the section is 0).
You cannot change the tableView style once set. So the only way is set the style during initialisation.
First, design your table cell on Storyboard whatever you want. Now, make a subclass of UITableViewCell and assign this class to your prototype custom cell which you have designed on Storyboard. Also, don't forget to set "reuse identifier in Storyboard table cell.
A view that presents data using rows in a single column. iOS 2.0+ iPadOS 2.0+ Mac Catalyst 13.1+ tvOS 9.0+
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With