Сбой при прокрутке 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 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;


}
  

Комментарии:

1. Не было бы НАМНОГО проще для вас и меньше кодирования, если бы вы сохранили свои значения в массиве / объекте? А может быть, подкласс UITableViewCell?

Ответ №1:

На самом деле вы не используете повторно ни одну ячейку, потому что вы выполняете всю часть внутри ячейки == ошибка кода nil, изменяя код примерно так

 - (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;

}
  

может вам немного помочь. Проверьте, не происходит ли сбой после замены кода на этот.

Ответ №2:

Где вы освобождаете все объекты, которые вы выделяете? Похоже, вы пытаетесь распределять одни и те же объекты снова и снова.

попробуйте следующий подход:

 UILabel  *lblTitle = [[[UILabel alloc] initWithFrame: cellRect1] autorelease];
  

Ответ №3:

Во-первых, механизм повторного использования ячейки не работает в вашем коде, потому что вы:

 static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
// ...
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"MyIdentifier"] autorelease];
  

Вы пытаетесь повторно использовать ячейку с идентификатором «Cell»? но когда вы создаете ячейку, вы создаете ее с помощью повторного идентификатора «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)