Iphone 滚动uitableview时崩溃
我有一个uitableview,滚动时崩溃 我尝试过泄漏、构建和分析,但无法解决此问题 获取以下错误Iphone 滚动uitableview时崩溃,iphone,uitableview,iphone-sdk-3.0,Iphone,Uitableview,Iphone Sdk 3.0,我有一个uitableview,滚动时崩溃 我尝试过泄漏、构建和分析,但无法解决此问题 获取以下错误 *** -[CALayer retain]: message sent to deallocated instance 0xe192280 下面是我正在运行的代码 // Customize the appearance of table view cells. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowA
*** -[CALayer retain]: message sent to deallocated instance 0xe192280
下面是我正在运行的代码
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
UIFont *font = [UIFont fontWithName:@"Arial" size:13];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"MyIdentifier"] autorelease];
NSInteger row = [indexPath row];
cellRect2 = CGRectMake(135, 10, 5, 20 );
lblColon = [[UILabel alloc] initWithFrame: cellRect2];
lblColon.font = font;
lblColon.backgroundColor = [UIColor clearColor];
lblColon.textColor = [UIColor blackColor];
[cell.contentView addSubview: lblColon];
lblColon.text = @":";
if (tableView == tblCompanyDetails) {
switch (indexPath.section)
{
case 0:
{
profileName = [appDelegate.arrCompanyProfile1 objectAtIndex:indexPath.row];
NSLog(@"appDelegate.arrCompanyProfile1 ------> %@", appDelegate.arrCompanyProfile1);
if(row == 0)
{
cellRect1 = CGRectMake(10, 10, 130, 20 );
lblTitle = [[UILabel alloc] initWithFrame: cellRect1];
//UIFont *font = [UIFont fontWithName:@"Arial" size:13];
lblTitle.font = font;
lblTitle.backgroundColor = [UIColor clearColor];
lblTitle.textColor = [UIColor blackColor];
[cell.contentView addSubview: lblTitle];
lblTitle.text = @"Company Name";
cellRect3 = CGRectMake( 145, 10, 180 ,20 );
lblResult = [[UILabel alloc] initWithFrame: cellRect3];
//UIFont *font = [UIFont fontWithName:@"Arial-BoldMT" size:14];
lblResult.font = font;
lblResult.backgroundColor = [UIColor clearColor];
lblResult.textColor = [UIColor blackColor];
[cell.contentView addSubview: lblResult];
//NSString *str = [profileName stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]];
//NSLog(@"str--------%@", str);
[lblResult setText:[NSString stringWithFormat: @"%@ ", profileName]];
break;
}
if(row == 1)
{
cellRect1 = CGRectMake(10, 10, 130, 20 );
lblTitle = [[UILabel alloc] initWithFrame: cellRect1];
//UIFont *font = [UIFont fontWithName:@"Arial" size:13];
lblTitle.font = font;
lblTitle.backgroundColor = [UIColor clearColor];
lblTitle.textColor = [UIColor blackColor];
[cell.contentView addSubview: lblTitle];
lblTitle.text = @"Type of Company";
cellRect3 = CGRectMake( 145, 10, 180 ,20 );
lblResult = [[UILabel alloc] initWithFrame: cellRect3];
//UIFont *font = [UIFont fontWithName:@"Arial-BoldMT" size:14];
lblResult.font = font;
lblResult.backgroundColor = [UIColor clearColor];
lblResult.textColor = [UIColor blackColor];
[cell.contentView addSubview: lblResult];
//NSLog(@"profileName.namelast--------%@", profileName);
//NSString *strLastName = [profileName stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]];
[lblResult setText:[NSString stringWithFormat: @"%@ ", profileName]];
break;
}
if(row == 2)
{
cellRect1 = CGRectMake(10, 10, 130, 20 );
lblTitle = [[UILabel alloc] initWithFrame: cellRect1];
//UIFont *font = [UIFont fontWithName:@"Arial" size:13];
lblTitle.font = font;
lblTitle.backgroundColor = [UIColor clearColor];
lblTitle.textColor = [UIColor blackColor];
[cell.contentView addSubview: lblTitle];
lblTitle.text = @"Main Contact Person";
cellRect3 = CGRectMake( 145, 10, 180 ,20 );
lblResult = [[UILabel alloc] initWithFrame: cellRect3];
//UIFont *font = [UIFont fontWithName:@"Arial-BoldMT" size:14];
lblResult.font = font;
lblResult.backgroundColor = [UIColor clearColor];
lblResult.textColor = [UIColor blackColor];
[cell.contentView addSubview: lblResult];
//NSString *strFirstName = [profileName stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]];
[lblResult setText:[NSString stringWithFormat: @"%@ ", profileName]];
break;
}
if(row == 3)
{
cellRect1 = CGRectMake(10, 10, 130, 20 );
lblTitle = [[UILabel alloc] initWithFrame: cellRect1];
//UIFont *font = [UIFont fontWithName:@"Arial" size:13];
lblTitle.font = font;
lblTitle.backgroundColor = [UIColor clearColor];
lblTitle.textColor = [UIColor blackColor];
[cell.contentView addSubview: lblTitle];
lblTitle.text = @"Address";
cellRect3 = CGRectMake( 145, 10, 180 ,20 );
lblResult = [[UILabel alloc] initWithFrame: cellRect3];
//UIFont *font = [UIFont fontWithName:@"Arial-BoldMT" size:14];
lblResult.font = font;
lblResult.backgroundColor = [UIColor clearColor];
lblResult.textColor = [UIColor blackColor];
[cell.contentView addSubview: lblResult];
//NSString *strFirstName = [profileName stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]];
[lblResult setText:[NSString stringWithFormat: @"%@ ", profileName]];
break;
}
if(row == 4)
{
cellRect1 = CGRectMake(10, 10, 130, 20 );
lblTitle = [[UILabel alloc] initWithFrame: cellRect1];
//UIFont *font = [UIFont fontWithName:@"Arial" size:13];
lblTitle.font = font;
lblTitle.backgroundColor = [UIColor clearColor];
lblTitle.textColor = [UIColor blackColor];
[cell.contentView addSubview: lblTitle];
lblTitle.text = @"City";
cellRect3 = CGRectMake( 145, 10, 180 ,20 );
lblResult = [[UILabel alloc] initWithFrame: cellRect3];
//UIFont *font = [UIFont fontWithName:@"Arial-BoldMT" size:14];
lblResult.font = font;
lblResult.backgroundColor = [UIColor clearColor];
lblResult.textColor = [UIColor blackColor];
[cell.contentView addSubview: lblResult];
//NSString *strFirstName = [profileName stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]];
[lblResult setText:[NSString stringWithFormat: @"%@ ", profileName]];
break;
}
if(row == 5)
{
cellRect1 = CGRectMake(10, 10, 100, 20 );
lblTitle = [[UILabel alloc] initWithFrame: cellRect1];
//UIFont *font = [UIFont fontWithName:@"Arial" size:13];
lblTitle.font = font;
lblTitle.backgroundColor = [UIColor clearColor];
lblTitle.textColor = [UIColor blackColor];
[cell.contentView addSubview: lblTitle];
lblTitle.text = @"State";
cellRect3 = CGRectMake( 145, 10, 180 ,20 );
lblResult = [[UILabel alloc] initWithFrame: cellRect3];
//UIFont *font = [UIFont fontWithName:@"Arial-BoldMT" size:14];
lblResult.font = font;
lblResult.backgroundColor = [UIColor clearColor];
lblResult.textColor = [UIColor blackColor];
[cell.contentView addSubview: lblResult];
//NSString *strFirstName = [profileName stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]];
[lblResult setText:[NSString stringWithFormat: @"%@ ", profileName]];
break;
}
if(row == 6)
{
cellRect1 = CGRectMake(10, 10, 130, 20 );
lblTitle = [[UILabel alloc] initWithFrame: cellRect1];
//UIFont *font = [UIFont fontWithName:@"Arial" size:13];
lblTitle.font = font;
lblTitle.backgroundColor = [UIColor clearColor];
lblTitle.textColor = [UIColor blackColor];
[cell.contentView addSubview: lblTitle];
lblTitle.text = @"Postal / Zip Code";
cellRect3 = CGRectMake( 145, 10, 180 ,20 );
lblResult = [[UILabel alloc] initWithFrame: cellRect3];
//UIFont *font = [UIFont fontWithName:@"Arial-BoldMT" size:14];
lblResult.font = font;
lblResult.backgroundColor = [UIColor clearColor];
lblResult.textColor = [UIColor blackColor];
[cell.contentView addSubview: lblResult];
//NSString *strFirstName = [profileName stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]];
[lblResult setText:[NSString stringWithFormat: @"%@ ", profileName]];
break;
}
if(row == 7)
{
cellRect1 = CGRectMake(10, 10, 130, 20 );
lblTitle = [[UILabel alloc] initWithFrame: cellRect1];
//UIFont *font = [UIFont fontWithName:@"Arial" size:13];
lblTitle.font = font;
lblTitle.backgroundColor = [UIColor clearColor];
lblTitle.textColor = [UIColor blackColor];
[cell.contentView addSubview: lblTitle];
lblTitle.text = @"Country";
cellRect3 = CGRectMake( 145, 10, 180 ,20 );
lblResult = [[UILabel alloc] initWithFrame: cellRect3];
//UIFont *font = [UIFont fontWithName:@"Arial-BoldMT" size:14];
lblResult.font = font;
lblResult.backgroundColor = [UIColor clearColor];
lblResult.textColor = [UIColor blackColor];
[cell.contentView addSubview: lblResult];
//NSString *strFirstName = [profileName stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]];
[lblResult setText:[NSString stringWithFormat: @"%@ ", profileName]];
break;
}
if(row == 8)
{
cellRect1 = CGRectMake(10, 10, 130, 20 );
lblTitle = [[UILabel alloc] initWithFrame: cellRect1];
//UIFont *font = [UIFont fontWithName:@"Arial" size:13];
lblTitle.font = font;
lblTitle.backgroundColor = [UIColor clearColor];
lblTitle.textColor = [UIColor blackColor];
[cell.contentView addSubview: lblTitle];
lblTitle.text = @"Primary Phone No.";
cellRect3 = CGRectMake( 145, 10, 180 ,20 );
lblResult = [[UILabel alloc] initWithFrame: cellRect3];
//UIFont *font = [UIFont fontWithName:@"Arial-BoldMT" size:14];
lblResult.font = font;
lblResult.backgroundColor = [UIColor clearColor];
lblResult.textColor = [UIColor blackColor];
[cell.contentView addSubview: lblResult];
//NSString *strFirstName = [profileName stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]];
[lblResult setText:[NSString stringWithFormat: @"%@ ", profileName]];
break;
}
if(row == 9)
{
cellRect1 = CGRectMake(10, 10, 130, 20 );
lblTitle = [[UILabel alloc] initWithFrame: cellRect1];
//UIFont *font = [UIFont fontWithName:@"Arial" size:13];
lblTitle.font = font;
lblTitle.backgroundColor = [UIColor clearColor];
lblTitle.textColor = [UIColor blackColor];
[cell.contentView addSubview: lblTitle];
lblTitle.text = @"Mobile No.";
cellRect3 = CGRectMake( 145, 10, 180 ,20 );
lblResult = [[UILabel alloc] initWithFrame: cellRect3];
//UIFont *font = [UIFont fontWithName:@"Arial-BoldMT" size:14];
lblResult.font = font;
lblResult.backgroundColor = [UIColor clearColor];
lblResult.textColor = [UIColor blackColor];
[cell.contentView addSubview: lblResult];
//NSString *strFirstName = [profileName stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]];
[lblResult setText:[NSString stringWithFormat: @"%@ ", profileName]];
break;
}
if(row == 10)
{
cellRect1 = CGRectMake(10, 10, 130, 20 );
lblTitle = [[UILabel alloc] initWithFrame: cellRect1];
//UIFont *font = [UIFont fontWithName:@"Arial" size:13];
lblTitle.font = font;
lblTitle.backgroundColor = [UIColor clearColor];
lblTitle.textColor = [UIColor blackColor];
[cell.contentView addSubview: lblTitle];
lblTitle.text = @"Toll Free No.";
cellRect3 = CGRectMake( 145, 10, 180 ,20 );
lblResult = [[UILabel alloc] initWithFrame: cellRect3];
//UIFont *font = [UIFont fontWithName:@"Arial-BoldMT" size:14];
lblResult.font = font;
lblResult.backgroundColor = [UIColor clearColor];
lblResult.textColor = [UIColor blackColor];
[cell.contentView addSubview: lblResult];
//NSString *strFirstName = [profileName stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]];
[lblResult setText:[NSString stringWithFormat: @"%@ ", profileName]];
break;
}
if(row == 11)
{
cellRect1 = CGRectMake(10, 10, 100, 20 );
lblTitle = [[UILabel alloc] initWithFrame: cellRect1];
//UIFont *font = [UIFont fontWithName:@"Arial" size:13];
lblTitle.font = font;
lblTitle.backgroundColor = [UIColor clearColor];
lblTitle.textColor = [UIColor blackColor];
[cell.contentView addSubview: lblTitle];
lblTitle.text = @"Websites";
cellRect3 = CGRectMake( 145, 10, 180 ,20 );
lblResult = [[UILabel alloc] initWithFrame: cellRect3];
//UIFont *font = [UIFont fontWithName:@"Arial-BoldMT" size:14];
lblResult.font = font;
lblResult.backgroundColor = [UIColor clearColor];
lblResult.textColor = [UIColor blackColor];
[cell.contentView addSubview: lblResult];
//NSString *strFirstName = [profileName stringByTrimmingCharactersInSet : [NSCharacterSet whitespaceAndNewlineCharacterSet]];
[lblResult setText:[NSString stringWithFormat: @"%@ ", profileName]];
break;
}
if(row == 12)
{
cellRect1 = CGRectMake(10, 10, 130, 20 );
lblTitle = [[UILabel alloc] initWithFrame: cellRect1];
//UIFont *font = [UIFont fontWithName:@"Arial" size:13];
lblTitle.font = font;
lblTitle.backgroundColor = [UIColor clearColor];
lblTitle.textColor = [UIColor blackColor];
[cell.contentView addSubview: lblTitle];
lblTitle.text = @"Email Address";
cellRect3 = CGRectMake( 145, 10, 180 ,20 );
lblResult = [[UILabel alloc] initWithFrame: cellRect3];
//UIFont *font = [UIFont fontWithName:@"Arial-BoldMT" size:14];
lblResult.font = font;
lblResult.backgroundColor = [UIColor clearColor];
lblResult.textColor = [UIColor blackColor];
[cell.contentView addSubview: lblResult];
//NSString *strFirstName = [profileName stringByTrimmingCharactersInSet : [NSCharacterSet whitespaceAndNewlineCharacterSet]];
[lblResult setText:[NSString stringWithFormat: @"%@ ", profileName]];
break;
}
if(row == 13)
{
cellRect1 = CGRectMake(10, 10, 130, 20 );
lblTitle = [[UILabel alloc] initWithFrame: cellRect1];
//UIFont *font = [UIFont fontWithName:@"Arial" size:13];
lblTitle.font = font;
lblTitle.backgroundColor = [UIColor clearColor];
lblTitle.textColor = [UIColor blackColor];
[cell.contentView addSubview: lblTitle];
lblTitle.text = @"Number of Employees";
cellRect3 = CGRectMake( 145, 10, 180 ,20 );
lblResult = [[UILabel alloc] initWithFrame: cellRect3];
//UIFont *font = [UIFont fontWithName:@"Arial-BoldMT" size:14];
lblResult.font = font;
lblResult.backgroundColor = [UIColor clearColor];
lblResult.textColor = [UIColor blackColor];
[cell.contentView addSubview: lblResult];
//NSString *strFirstName = [profileName stringByTrimmingCharactersInSet : [NSCharacterSet whitespaceAndNewlineCharacterSet]];
[lblResult setText:[NSString stringWithFormat: @"%@ ", profileName]];
break;
}
if(row == 14)
{
cellRect1 = CGRectMake(10, 10, 130, 20 );
lblTitle = [[UILabel alloc] initWithFrame: cellRect1];
//UIFont *font = [UIFont fontWithName:@"Arial" size:13];
lblTitle.font = font;
lblTitle.backgroundColor = [UIColor clearColor];
lblTitle.textColor = [UIColor blackColor];
[cell.contentView addSubview: lblTitle];
lblTitle.text = @"Legal structure";
cellRect3 = CGRectMake( 145, 10, 180 ,20 );
lblResult = [[UILabel alloc] initWithFrame: cellRect3];
//UIFont *font = [UIFont fontWithName:@"Arial-BoldMT" size:14];
lblResult.font = font;
lblResult.backgroundColor = [UIColor clearColor];
lblResult.textColor = [UIColor blackColor];
[cell.contentView addSubview: lblResult];
//NSString *strFirstName = [profileName stringByTrimmingCharactersInSet : [NSCharacterSet whitespaceAndNewlineCharacterSet]];
[lblResult setText:[NSString stringWithFormat: @"%@ ", profileName]];
break;
}
}
case 1:
{
profileName = [appDelegate.arrCompanyProfile2 objectAtIndex:indexPath.row];
if(row == 0)
{
cellRect1 = CGRectMake(10, 10, 100, 20 );
lblTitle = [[UILabel alloc] initWithFrame: cellRect1];
//UIFont *font = [UIFont fontWithName:@"Arial" size:13];
lblTitle.font = font;
lblTitle.backgroundColor = [UIColor clearColor];
lblTitle.textColor = [UIColor blackColor];
[cell.contentView addSubview: lblTitle];
lblTitle.text = @"Primary";
cellRect3 = CGRectMake( 145, 10, 180 ,20 );
lblResult = [[UILabel alloc] initWithFrame: cellRect3];
//UIFont *font = [UIFont fontWithName:@"Arial-BoldMT" size:14];
lblResult.font = font;
lblResult.backgroundColor = [UIColor clearColor];
lblResult.textColor = [UIColor blackColor];
[cell.contentView addSubview: lblResult];
[lblResult setText:[NSString stringWithFormat: @"%@ ", profileName]];
break;
}
if(row == 1)
{
cellRect1 = CGRectMake(10, 10, 120, 20 );
lblTitle = [[UILabel alloc] initWithFrame: cellRect1];
//UIFont *font = [UIFont fontWithName:@"Arial" size:13];
lblTitle.font = font;
lblTitle.backgroundColor = [UIColor clearColor];
lblTitle.textColor = [UIColor blackColor];
[cell.contentView addSubview: lblTitle];
lblTitle.text = @"Secondary";
cellRect3 = CGRectMake( 145, 10, 180 ,20 );
lblResult = [[UILabel alloc] initWithFrame: cellRect3];
//UIFont *font = [UIFont fontWithName:@"Arial-BoldMT" size:14];
lblResult.font = font;
lblResult.backgroundColor = [UIColor clearColor];
lblResult.textColor = [UIColor blackColor];
[cell.contentView addSubview: lblResult];
//NSLog(@"profileName section2 ----> %@", profileName);
//NSString *strFirstName = [profileName stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]];
[lblResult setText:[NSString stringWithFormat: @"%@ ", profileName]];
break;
}
if(row == 2)
{
cellRect1 = CGRectMake(10, 10, 130, 20 );
lblTitle = [[UILabel alloc] initWithFrame: cellRect1];
//UIFont *font = [UIFont fontWithName:@"Arial" size:13];
lblTitle.font = font;
lblTitle.backgroundColor = [UIColor clearColor];
lblTitle.textColor = [UIColor blackColor];
[cell.contentView addSubview: lblTitle];
lblTitle.text = @"No of years in business";
cellRect3 = CGRectMake( 145, 10, 180 ,20 );
lblResult = [[UILabel alloc] initWithFrame: cellRect3];
//UIFont *font = [UIFont fontWithName:@"Arial-BoldMT" size:14];
lblResult.font = font;
lblResult.backgroundColor = [UIColor clearColor];
lblResult.textColor = [UIColor blackColor];
[cell.contentView addSubview: lblResult];
//NSString *strFirstName = [profileName stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]];
[lblResult setText:[NSString stringWithFormat: @"%@ ", profileName]];
break;
}
}
case 2:
{
profileName = [appDelegate.arrCompanyProfile3 objectAtIndex:indexPath.row];
if(row == 0)
{
cellRect1 = CGRectMake(10, 10, 130, 20 );
lblTitle = [[UILabel alloc] initWithFrame: cellRect1];
//UIFont *font = [UIFont fontWithName:@"Arial" size:13];
lblTitle.font = font;
lblTitle.backgroundColor = [UIColor clearColor];
lblTitle.textColor = [UIColor blackColor];
[cell.contentView addSubview: lblTitle];
lblTitle.text = @"Postal / Zip Code";
cellRect3 = CGRectMake( 145, 10, 180 ,20 );
lblResult = [[UILabel alloc] initWithFrame: cellRect3];
//UIFont *font = [UIFont fontWithName:@"Arial-BoldMT" size:14];
lblResult.font = font;
lblResult.backgroundColor = [UIColor clearColor];
lblResult.textColor = [UIColor blackColor];
[cell.contentView addSubview: lblResult];
[lblResult setText:[NSString stringWithFormat: @"%@ ", profileName]];
break;
}
if(row == 1)
{
cellRect1 = CGRectMake(10, 10, 130, 20);
lblTitle = [[UILabel alloc] initWithFrame: cellRect1];
//UIFont *font = [UIFont fontWithName:@"Arial" size:13];
lblTitle.font = font;
lblTitle.backgroundColor = [UIColor clearColor];
lblTitle.textColor = [UIColor blackColor];
[cell.contentView addSubview: lblTitle];
lblTitle.text = @"Coverage Area (miles)";
cellRect3 = CGRectMake(145, 10, 180 ,20);
lblResult = [[UILabel alloc] initWithFrame: cellRect3];
//UIFont *font = [UIFont fontWithName:@"Arial-BoldMT" size:14];
lblResult.font = font;
lblResult.backgroundColor = [UIColor clearColor];
lblResult.textColor = [UIColor blackColor];
[cell.contentView addSubview: lblResult];
//NSString *strFirstName = [profileName stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]];
[lblResult setText:[NSString stringWithFormat: @"%@ ", profileName]];
break;
}
}
case 3:
{
profileName = [appDelegate.arrCompanyProfile4 objectAtIndex:indexPath.row];
if(row == 0)
{
lblColon.hidden = YES;
cellRect3 = CGRectMake(10, 10, 280, 40);
lblResult = [[UILabel alloc] initWithFrame: cellRect3];
//UIFont *font = [UIFont fontWithName:@"Arial-BoldMT" size:14];
lblResult.font = font;
lblResult.backgroundColor = [UIColor clearColor];
lblResult.textColor = [UIColor blackColor];
[cell.contentView addSubview: lblResult];
[lblResult setText:[NSString stringWithFormat: @"%@ ", profileName]];
break;
}
}
case 4:
{
profileName = [appDelegate.arrCompanyProfile5 objectAtIndex:indexPath.row];
if(row == 0)
{
lblColon.hidden = YES;
cellRect3 = CGRectMake(10, 10, 100, 20);
lblResult = [[UILabel alloc] initWithFrame: cellRect3];
lblResult.font = font;
lblResult.backgroundColor = [UIColor clearColor];
lblResult.textColor = [UIColor blackColor];
[cell.contentView addSubview: lblResult];
[lblResult setText:[NSString stringWithFormat: @"%@ ", profileName]];
break;
}
}
case 5:
{
if(row == 0)
{
lblColon.hidden = YES;
cellRect3 = CGRectMake(10, 10, 100, 20);
lblResult = [[UILabel alloc] initWithFrame: cellRect3];
lblResult.font = font;
lblResult.backgroundColor = [UIColor clearColor];
lblResult.textColor = [UIColor blackColor];
[cell.contentView addSubview: lblResult];
break;
}
}
}
}
}
return cell;
}
您将在何处释放正在分配的所有对象?看起来您正试图一次又一次地分配相同的对象 尝试以下方法:
UILabel *lblTitle = [[[UILabel alloc] initWithFrame: cellRect1] autorelease];
实际上,您没有重用任何单元格,因为您正在执行单元格内的所有部分==nil code bloack,并对代码进行如下更改
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
UIFont *font = [UIFont fontWithName:@"Arial" size:13];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"MyIdentifier"] autorelease];
UILabel* lblColon = [[UILabel alloc] initWithFrame:CGRectMake(135, 10, 5, 20 )];
lblColon.font = font;
lblColon.backgroundColor = [UIColor clearColor];
lblColon.textColor = [UIColor blackColor];
lblColon.text = @":";
[lblColon setTag:222];
[cell.contentView addSubview: lblColon];
[lblColon release];
}
NSInteger row = [indexPath row];
UILabel* lblToReuse = (UILabel*)[cell.contentView viewWithTag:222];
if (tableView == tblCompanyDetails) {
//usual things you were doing earlier
}
return cell;
}
也许能帮你一点忙。用这个替换代码后,检查它是否仍然崩溃。首先,重用单元的机制在代码中不起作用,因为您:
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
// ...
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"MyIdentifier"] autorelease];
您正在尝试重用标识符为“cell”的单元格?但当您创建单元格时,您使用reuseIdentifier“MyIdentifier”创建它。这很糟糕。您应该创建具有相同标识符的单元格:
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
并将用于单独配置单元格的部分(取决于indexPath)移动到if(cell==nil){
语句之外。在此语句中,您应该只对单元格进行全局配置。在此处,仅为此tanle视图中的所有单元格配置相同的内容。因为此单元格将被其他单元格重用
当我们对单元使用重用机制时,它会尝试查找具有标识符的单元(调用[tableView dequeueReusableCellWithIdentifier:CellIdentifier]
)。如果找不到,则创建具有相同标识符的单元原型
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"MyIdentifier"] autorelease];
}
在这部分代码之后,将当前单元格的特定代码(在指定的indexPath中)如果将值存储在数组/对象中,或者将值存储在UITableViewCell子类中,对您来说不是更容易、编码更少吗?