在iOS中滚动时如何禁用重新加载tableview
我想在滚动时禁用重新加载表视图。现在,当用户滚动uitableview时,调用了我的应用程序。在srcolling时如何禁用它?请给我一些建议。提前谢谢在iOS中滚动时如何禁用重新加载tableview,ios,objective-c,cocoa-touch,uitableview,Ios,Objective C,Cocoa Touch,Uitableview,我想在滚动时禁用重新加载表视图。现在,当用户滚动uitableview时,调用了我的应用程序。在srcolling时如何禁用它?请给我一些建议。提前谢谢 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSString *CellIdentifier = [NSString stringWithFormat:@"%d,%
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *CellIdentifier = [NSString stringWithFormat:@"%d,%d",indexPath.section,indexPath.row];
UITableViewCell *cell = [_tableView dequeueReusableCellWithIdentifier:CellIdentifier];
UILabel *FileNameLabel;
UILabel *UploadTimeLabel;
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
CFileNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(40, 0, 130, 30)];
UploadTimeLabel = [[UILabel alloc] initWithFrame:CGRectMake(40, 20, 130, 25)];
FileNameLabel.tag = 1000;
FileNameLabel.backgroundColor = [UIColor clearColor];
FileNameLabel.font = [UIFont fontWithName:@"Helvetica" size:14];
FileNameLabel.font = [UIFont boldSystemFontOfSize:14];
FileNameLabel.textColor = [UIColor blackColor];
// FileNameLabel.text =[temp objectAtIndex:indexPath.row];
[cell.contentView addSubview: FileNameLabel];
[FileNameLabel release];
UploadTimeLabel.tag = 2000;
UploadTimeLabel.backgroundColor = [UIColor clearColor];
UploadTimeLabel.font = [UIFont fontWithName:@"Helvetica" size:12];
UploadTimeLabel.textColor = [UIColor grayColor];
// UploadTimeLabel.text = [UploadTimeArray objectAtIndex:indexPath.row];
[cell.contentView addSubview: UploadTimeLabel];
[UploadTimeLabel release];
}
if( [OriginalArray count] > 0)
{
UILabel *fileNameLbl = (UILabel*)[cell.contentView viewWithTag:1000];
//fileNameLbl.text =[temp objectAtIndex:indexPath.row];
fileNameLbl.text =[[OriginalArray valueForKey:@"FILENAME"] objectAtIndex:indexPath.row];
UILabel *uploadlbl = (UILabel*)[cell.contentView viewWithTag:2000];
uploadlbl.text =[[OriginalArray valueForKey:@"UPLOADTIME"] objectAtIndex:indexPath.row];
}
_tableView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
return cell;
}
滚动tableview时,无法阻止调用
cellForRowAtIndexPath:
。如果某件事不必每次都发生,你可以把它保持在“如果”状态
if (cell == nil)
{
//Functionality goes here when it not needed to happen every time.
}
不要实现方法
UITableViewCell*cell=[tableView dequeueReusableCellWithIdentifier:@“yourID”]代码>或UITableViewCell*单元格=[tableView dequeueCellWithReuseIdentifier:nil]代码>
这将阻止表视图重用单元格。但是,如果tableview包含大量单元格,这不是一个好主意。希望这有帮助。:) 您可以使用数据源,而不是试图避免重新加载数据,这样数据就不会改变。我希望你明白我的意思 使用dequecellforrowatindex方法避免单元格重新加载。这是正确的,每当单元格滚动到视图中时,它将来自cellForRowAtIndexPath
。请为建议的函数创建注释或提供一些源代码。您能提供一些示例吗,老兄,你可能会认为在iOS中多年的开发工作会让你记住数据源是至关重要的……谢谢你提醒我。我遇到了一个问题,我正在过滤联系人,当我去滚动数据时,数据不会正确更新。。。是因为我的数据源没有指向过滤后的数据。我感到困惑。非常感谢。