我在 SnowLeopard 上使用 Xcode 4.2,我的项目正在使用故事板。我正在尝试实施一个UITableView
具有 2 种不同的自定义细胞类型,sessionCell
and infoCell
。我可以让这两种类型出现在同一个列表中,但现在我遇到了新问题?!这sessionCell
显示一次,然后 X 个infoCells
显示在它之后 - 正如我想要的 - 除了第一个infoCell
总是被覆盖sessionCell
!
- (NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section
{
return [self.people count];
}
//inside cellForRowAtIndexPath
if(indexPath.row == 0) {
cell = [tableView dequeueReusableCellWithIdentifier:@"sessionCell"];
} else {
cell = [tableView dequeueReusableCellWithIdentifier:@"infoCell"];
}
...
return cell;
我试着说return array count + 1
,甚至硬编码return 7
(它适合我的例子)但两者都不正确!
myObject *person = [self.people objectAtIndex:indexPath.row];
或者我的问题出在上面这一行?我什至尝试过indexPath.row+1
...
任何帮助将不胜感激!!
如果我正确理解你的问题,首先infoCell
(第二UITableView
row) 应该显示第一人称对象的数据,对吧?
那么看来你想要:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *sessionCellID = @"sessionID";
static NSString *infoCellID = @"infoID";
if( indexPath.row == 0 ) {
SessionCellClass *cell = nil;
cell = (SessionCellClass *)[tableView dequeueReusableCellWithIdentifier:sessionCellID];
if( !cell ) {
// do something to create a new instance of cell
// either alloc/initWithStyle or load via UINib
}
// populate the cell with session model
return cell;
}
else {
InfoCellClass *cell = nil;
cell = (InfoCellClass *)[tableView dequeueReusableCellWithIdentifier:infoCellID];
if( !cell ) {
// do something to create a new instance of info cell
// either alloc/initWithStyle or load via UINib
// ...
// get the model object:
myObject *person = [[self people] objectAtIndex:indexPath.row - 1];
// populate the cell with that model object
// ...
return cell;
}
}
你需要返回[[self people] count] + 1
对于行数:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [[self people] count] + 1;
}
这样第 n 行显示第 (n-1) 个数据。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)