我很擔心這個問題。我有一個NSArray *列表,它包含一個plist文件中的70個元素。現在我需要將它們填充到UITableView。 我想要的是一次顯示20個項目,然後單擊第21個單元格以顯示另一個20 ..然後按第41個單元格以顯示另外20個項目...等等,直到所有72個單元格都顯示出來..一次顯示一定數量的行,單擊按鈕,顯示更多
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
return 20;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
static NSString *addCellID = @"addMoreCell";
UITableViewCell *addCell = [tableView dequeueReusableCellWithIdentifier:addCellID];
if (indexPath.row == 0) {
static NSString *CellIdentifier = @"labelCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
return cell;
} else if (indexPath.row < 25){
NSDictionary *dic = [self.list objectAtIndex:indexPath.row];
cell.textLabel.text = [dic objectForKey:@"Title"];
cell.detailTextLabel.text = [dic objectForKey:@"Tips"];
return cell;
} else {
if (cell == nil) {
addCell.textLabel.text = @"Load More...";
return cell;
}
}
}
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.row == 20)
{
[self.tableView reloadData];
}
}
調查UITableView部分http://www.iphonesdkarticles.com/2009/01/uitableview-sectioned-table-view.html – FaddishWorm