![](/img/trans.png)
[英]How to show last add cell on UITableview whileloading view or reloading tableview?
[英]View last cell when i add array of cell in tableview
我需要在tableview单元格中显示最后一个单元格记录。 每次我将在表视图中添加新数组。 之后,我将重新加载tableview单元格。 现在,它显示了第一个单元格中的记录。 任何人都请给我建议如何显示最后一个单元格。
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"TrackDataTimeCell";
TrackDataTimeCell *cell = (TrackDataTimeCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
@autoreleasepool {
[[NSBundle mainBundle] loadNibNamed:@"TrackDataTimeCell" owner:self options:nil];
cell = (TrackDataTimeCell *) cellChallengeFriends;
cellChallengeFriends = nil;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
}
if (!cell) {
cell =(TrackDataTimeCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
UIActivityIndicatorView *activityIndicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
cell.accessoryView = activityIndicatorView;
}
NSArray *tableData = [NSArray arrayWithObjects:@"Egg Benedict", @"Mushroom Risotto", nil];
NSArray *tableData1 = [NSArray arrayWithObjects:@"test1", @"test2", nil];
[cell.deleteButton addTarget:self action:@selector(deleteButtonAction:) forControlEvents:UIControlEventTouchUpInside];
cell.deleteButton.tag = indexPath.row;
cell.nameList.text= [tableData objectAtIndex:indexPath.row];
cell.marklist.text= [tableData1 objectAtIndex:indexPath.row];
return cell;
}
- (IBAction)addBillingItems:(id)sender
{
rowVal=rowVal+1;
[nameList addObject: self.codeAdd.text];
[marklist addObject: selectDate];
[tbl reloadData];
}
请在http://postimg.org/image/g0dzs0r2p/查看示例图片
我有5个牢房。 现在显示的是前四个。 滚动后显示5,但我希望最后一次显示单元格。 请帮我
您必须少设置tableview框架。如果您有iPhone tableview框架,则将框架设置为cgrectmake(0,0,320,430)。如果那不能解决您的问题,请添加uitableview:viewforheaderinsection方法。只需添加uiview并将框架设置为cgrectmake( 0,0,320,1)。这将设置表格的框架并显示所有单元格。
您可以使用它来自动滚动到最后插入的单元格。
CGPoint bottomOffset = CGPointMake(0, self.tableView.contentSize.height - self.tableView.bounds.size.height + 150);
if ( bottomOffset.y > 0 ) {
[self.tableView setContentOffset:bottomOffset animated:YES];
}
150的值是在tableView中的单元格之后添加额外的空间。 它是可选的,即如果您想要在单元格后留出更多空间,则可以使用它
有一个简单的解决方案可以解决您的问题。 只需使用tableView的方法
[tbl scrollToRowAtIndexPath:[NSIndexPath indexPathForRow: rowVal inSection:0]
atScrollPosition:UITableViewScrollPositionBottom
animated:YES];
只需在[tbl reloadData]
之后调用它
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.