在表格视图中滚动时应用冻结



我的应用程序在表格视图中滚动时冻结。它加载数据,但是当我尝试滚动时,应用程序会立即冻结。问题出在哪里?我的cellforrowatindexpath方法是:

if (cell == nil) { 
    cell = [[[NSBundle mainBundle] loadNibNamed:@"MyCellView" owner:self options:nil]objectAtIndex:0];
}
getDats *gDatas=[[[getDats alloc]init]autorelease];
gDatas=[self.bookmarks objectAtIndex:indexPath.row];
const char *prior = "High"; 
const char *prior1 =[gDatas.Priority UTF8String]; 
if (strcmp(prior1 , prior) == 0)
 {
    NSString *imagePath = [[NSBundle mainBundle]pathForResource:@"highPriority" ofType:@"png"]; 
cell.imageView.image = [UIImage imageWithContentsOfFile:imagePath];   
}
[cell.MOwner setText:gDatas.WhatId];
[cell.DueDate setText:gDatas.EndDateTime];
[cell.theTextLabel setText:gDatas.Subject];
[cell.Descri setText:gDatas.Desc];
[cell.TaskId setText:[NSString stringWithFormat:@"%d" , gDatas.rowId]];  
cell.backgroundView.backgroundColor = [UIColor scrollViewTexturedBackgroundColor];
return cell;

调试器显示:

-[__NSCFString优先级]:发送到实例0x7341790的无法识别的选择器 2012-07-09 10:23:46.761 MeetingMaker[716:207] * 由于未捕获的异常"NSInvalidArgumentException"而终止应用程序,原因:"-[__NSCFString优先级]:无法识别的选择器发送到实例0x7341790" * 第一次抛出调用堆栈: (0x1cbf052 0x2152d0a 0x1cc0ced 0x1c25f00 0x1c25ce2 0xf449 0x4e7e0f 0x4e8589 0x4d3dfd 0x4e2851 0x48d301 0x1cc0e72 0x29492d 0x29e827 0x224fa7 0x226ea6 0x2c037a 0x2c01af 0x1c93966 0x1c93407 0x1bf67c0 0x1bf5db4 0x1bf5ccb 0x2656879 0x265693e 0x44ea9b 0xe0c2 0x1e15) 终止称为抛出异常 (GDB) 。

该应用程序在线显示错误:

const char *prior1 =[gDatas.Priority UTF8String]; 

和节目

线程:程序接收信号SIGABRT。

您需要重用您的单元格,当您向下滚动 UITableView 时,不再在视图中的单元格将被重用,为此您需要为单元格设置 resuseIdentifier。

来自 UITableViewCell 文档

reuseIdentifier
A string used to identify a cell that is reusable. (read-only)
@property(nonatomic, readonly, copy) NSString *reuseIdentifier
Discussion
The reuse identifier is associated with a UITableViewCell object that the table-view’s delegate creates with the intent to reuse it as the basis (for performance reasons) for multiple rows of a table view. It is assigned to the cell object in initWithFrame:reuseIdentifier: and cannot be changed thereafter. A UITableView object maintains a queue (or list) of the currently reusable cells, each with its own reuse identifier, and makes them available to the delegate in the dequeueReusableCellWithIdentifier: method.

因此,您应该从这样的东西开始您的方法:

static NSString *CellIdentifier = @"Cell";  
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
 if (cell == nil) {      
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 

}

最新更新