【发布时间】:2011-05-28 05:26:23
【问题描述】:
嘿, 谁能指导我完成这个我在表中有大约 15 个条目我希望另外 15 个条目在最后一个 UITableViewCell 中提供更多负载。谁能帮帮我?
【问题讨论】:
标签: objective-c cocoa-touch uitableview ios4
嘿, 谁能指导我完成这个我在表中有大约 15 个条目我希望另外 15 个条目在最后一个 UITableViewCell 中提供更多负载。谁能帮帮我?
【问题讨论】:
标签: objective-c cocoa-touch uitableview ios4
在表格视图中显示一个额外的行,在
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return dataRows+1;
}
在
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
//after setting tableviewcell
if(indexPath.row==dataRows){
cell.textLabel.text=@"Load More Rows";
}
}
在
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.row==dataRows){
//there you can write code to get next rows
}
}
您需要根据显示的行更新 numberOfRows 变量。
编辑:获取额外条目后,您可以使用以下方法将它们添加到现有条目数组中。您的原始数组应该是 NSMutableArray 才能使用此方法。
[originalEntriesArray addObjectsFromArray:extraEntriesArray];
【讨论】:
numberOfRows = [yourEntriesArray count] + 1; 使其更清晰。
我写了一个例子项目就是这样做的。从 GitHub 下载 https://github.com/Abizern/PartialTable
【讨论】:
beginUpdate和endUpdate更新tableView的部分
我写了一些可能有用的东西:https://github.com/nmondollot/NMPaginator
它封装了分页,几乎可以与任何使用 page 和 per_page 参数的 Web 服务一起使用。它还具有 UITableView,当您向下滚动时会自动获取下一个结果。
【讨论】:
希望对你有帮助
我取了一个可变数组和一个整数变量,并将数组的总数设置为整数变量
arr = [[NSMutableArray alloc]initWithObjects:@"Radix",@"Riki", nil]; dataRows = [arr 计数];然后我根据表格的数据源方法中的整数变量设置部分中的行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { // 返回节中的行数。 返回数据行+1; }因为你最后想要一个额外的单元格。
现在是时候设置表格单元格的文本了
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{ 静态 NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell...
//setting the text of the cell as per Mutable array
if (indexPath.row < [arr count]) {
cell.textLabel.text = [arr objectAtIndex:indexPath.row];
}
//setting the text of the extra cell
if (indexPath.row == dataRows) {
cell.textLabel.text = @"more cells";
}
return cell;
}
现在点击更多单元格,您需要额外的单元格,所以只需在
中添加您的代码 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath方法,意味着你必须做这样的事情
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if(indexPath.row == dataRows) { //请为exra细胞编码 } }运行您的应用以检查此代码。
【讨论】: