我在Interface Builder中创建了一个静态表,其中包含6个部分,所有部分都有不同的行数.我现在想要添加具有不同行数的第7个部分.
首先,一旦我取消注释Xcode插入的标准表委托方法,我就会在self.tableView.tableHeaderView = containerView中崩溃; 我在表格中添加了一个标题.
更重要的是,我正在使用以下代码崩溃
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 7;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (section==6) {
return 4;
} else {
return [super tableView:tableView numberOfRowsInSection:section];
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{/*
if (indexPath.section == 6) {
static NSString *CellIdentifier = @"cellWireless";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
// Configure the cell...
return cell;
}*/
return [super tableView:tableView cellForRowAtIndexPath:indexPath];
}
Run Code Online (Sandbox Code Playgroud)
如何正确地保留现有部分,但添加一个带有几个单元格的部分?
我有一个带故事板的应用程序.在一个场景中,我有一个带有静态单元格内容的tableview.是否可以将背景选择的颜色更改为默认选项(蓝色和灰色)中的另一种颜色?
我知道如果我可以在forRowAtIndexPath中更改单元格背景颜色,但在这种情况下我没有tableview中的任何数据源函数.我确信可以通过IB或其他功能修改...
提前致谢!
我在storyboard文件中创建了一个标识符为"mainViewTableCell"的原型单元格,并将主表视图与名为"NTTableViewController"的自定义控制器类连接起来.我在NTTableViewController.m中实现了函数"tableView cellForRowAtIndexPath",如下所示:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString* MAINVIEW_CELLIDENTIFIER = @"mainViewTableCell";
UITableViewCell *newCell = [tableView dequeueReusableCellWithIdentifier: MAINVIEW_CELLIDENTIFIER];
if (newCell == nil) {
newCell = [[UITableViewCell alloc] initWithStyle: UITableViewCellStyleSubtitle reuseIdentifier: MAINVIEW_CELLIDENTIFIER];
[newCell autorelease];
newCell.selectionStyle = UITableViewCellSelectionStyleNone;
}
NTContactItem* currentItem = [self.contactItemContainer objectInContainerAtIndex: indexPath.row];
NSString* firstName = currentItem.firstName;
NSString* lastName = currentItem.lastName;
NSString* fullName = [firstName stringByAppendingFormat: lastName];
[newCell.textLabel setText: fullName];
[newCell.detailTextLabel setText: currentItem.mobilePhone];
return newCell;
}
Run Code Online (Sandbox Code Playgroud)
但我继续从dequeueReusableCellWithIdentifier获取nil,并且每次都必须创建一个新的cell实例.
那么,有什么不对?
代码:项目
谢谢大家.
objective-c ×2
uitableview ×2
xcode ×2
cocoa-touch ×1
ios ×1
storyboard ×1
tableview ×1
uikit ×1