我使用 Interface Builder (IB) 在 iPhone 应用程序中创建了一个 TableView 。我的表格样式设置为分组,并在 IB 中以这种方式显示。但是,每当我构建并运行时,它都会在模拟器中显示为 Plain 样式。
我将另一个 View 设置为分组,但没有遇到此问题。以前有人遇到过这个问题吗?
View 的其余部分不是以编程方式创建的,所以我想避免为这个 View 这样做。一定有我遗漏的东西。
我在其中执行大部分操作的唯一 tableView 方法是单元格处理程序方法,在该方法中我将文本框合并到选择字段中:
- (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;
最佳答案
我们有这个,它难住了我们大约一个小时。最后我们发现我们未能在导航 Controller 内设置 View Controller 的 NIB Name 属性(在选项卡栏 Controller 内,在我们的主 XIB 中!)。如果没有该设置,我们对 TableView 的 XIB 文件所做的所有更改都将被完全忽略。然而,代码在其他方面运行良好,几乎没有指出我们的错误。
我敢打赌,您的情况与此类似。确保您的 XIB(您设置表格样式的位置)实际被使用。
关于iphone - IB、UITableView 分组样式设置不生效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1775528/