2012-11-23 18 views
0

大家好我有一个大问题,我正在开发一个iPad应用程序。在这个我已经重用UITableView中的表视图单元格。早些时候,我没有重复使用这些单元,它工作但速度很慢。为了提高性能,我已经rused细胞现在是非常快的,但是当我滚动多次或速度那么* EXC_BAD_ACCESS *发生与以下消息:滚动多次意外的EXC_BAD_ACCESS UITableView

-[CALayer retain]: message sent to deallocated instance 0x5aba7b0 

我发现它被释放的实际IBOutlet中。这是UIImageView。在它之前它与单元格中的UIButton相同的问题。我用保留财产宣布它,然后解决。现在,如果我声明图像视图保留它的作品,但现在..prob是我需要2类imageViews根据单元格的位置或奇数。现在它显示相同的图像浏览..继续3,2,4 ..细胞不固定。我有问题strugling请帮的代码如下:还有一件事我装3型细胞,所以我已经存储cellIdientifier在缺陷对象

#import <Foundation/Foundation.h> 
#import "BaseTableDelegate.h" 

@interface AssignResponsibilityTableDelegate : BaseTableDelegate { 

//Assign Responsibility Table cell IBOutlet 
IBOutlet UITableViewCell *assignResponsibilityTableCustomCell; 
IBOutlet UIButton *assignResCellViewButton; 
IBOutlet UIButton *assignResCellNoteButton; 
IBOutlet UILabel *assignREsCellDetailLabel; 
IBOutlet UIImageView *assignResImageView; 
IBOutlet UILabel *assignREsCellElementlabel; 

//Trade 
IBOutlet UIView *tradeSpinnerBackgroundView;  
IBOutlet UITextView *tradeTextView;  
IBOutlet UITextView *tradeSelectedNameTextView;  
IBOutlet UIButton *tradeSpinnerButton; 

//SubContractor 
IBOutlet UIView *subcontractorSpinnerView;  
IBOutlet UITextView *subContractorTextView; 
IBOutlet UITextView *subContractorSelectedNameTextView;  
IBOutlet UIButton *subContractorSpinnerButton; 

UIImage* greenLenseImage; 
UIImage* lenceImage; 
UIImage* noteExistImage; 
UIImage* noteNotExistImage; 

NSMutableArray* assignDefects; 

// int cellHeight; 
} 

@property(nonatomic, retain)UITextView *subContractorSelectedNameTextView; 
@property(nonatomic, retain)UITextView *tradeSelectedNameTextView; 
@property(nonatomic, retain)UIButton *tradeSpinnerButton; 
@property(nonatomic, retain)UIView *tradeSpinnerBackgroundView; 
@property(nonatomic, retain)UIView *subcontractorSpinnerView; 

//Assign Responsibility Table Cell Click Action 
- (IBAction)tradeContractorButtonClicked:(id)sender; 
- (IBAction)subContractorButtonClicked:(id)sender; 

@end 

以下是的cellForRowAtIndexPath:


- (UITableViewCell *)tableView:(UITableView *)tableView 
     cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    Defect* defect=nil; 

    if(defects && [defects count]>0){ 

     defect=[defects objectAtIndex:indexPath.row]; 
    } 

    UITableViewCell *cell=nil; 
    cell = [tableView dequeueReusableCellWithIdentifier:defect.cellIdientifier]; 
    NSLog(@"%@",cell.reuseIdentifier); 

    int row = [indexPath row]; 

    if (cell == nil) { 

     NSLog(@"+++++++++++++++++++++++++++888Button=%@",assignResCellViewButton); 
     NSLog(@"Button=%@",subContractorSpinnerButton); 
     NSLog(@"Button=%@",tradeSpinnerButton); 
     NSLog(@"Button=%@",assignResCellNoteButton); 

    NSLog(@"assignResponsibilityTableCustomCell=%@",assignResponsibilityTableCustomCell); 
     NSLog(@"assignResCellViewButton=%@",assignResCellViewButton); 
     NSLog(@"assignResCellNoteButton=%@",assignResCellNoteButton); 
     NSLog(@"tradeSpinnerButton=%@",tradeSpinnerButton); 
     NSLog(@"subContractorSpinnerButton=%@",subContractorSpinnerButton); 
     NSLog(@"assignREsCellElementlabel=%@",assignREsCellElementlabel); 
     NSLog(@"assignREsCellDetailLabel=%@",assignREsCellDetailLabel); 
     NSLog(@"assignResImageView=%@",assignResImageView); 
     NSLog(@"tradeTextView=%@",tradeTextView); 
     NSLog(@"subContractorTextView=%@",subContractorTextView); 
     NSLog(@"tradeSelectedNameTextView=%@",tradeSelectedNameTextView); 

     NSLog(@"subContractorSelectedNameTextView=%@",subContractorSelectedNameTextView); 
     NSLog(@"tradeSpinnerBackgroundView=%@",tradeSpinnerBackgroundView); 
     NSLog(@"subcontractorSpinnerView=%@",subcontractorSpinnerView); 
       NSLog(@"++++++++++++++++++++999Button=%@",statusButton); 

     //Load Nib as per Text Length 
     [self getCellNibName:defect]; 

     //[[NSBundle mainBundle] loadNibNamed:@"AssignResponsibilityCellItem" owner:self options:nil]; 
     cell=assignResponsibilityTableCustomCell; 
     assignResCellViewButton.tag=VIEW_BUTTON_TAG; 
     assignResCellNoteButton.tag=NOTE_BUTTON_TAG; 
     tradeSpinnerButton.tag=TRADE_SPINNER_BUTTON_TAG; 
     subContractorSpinnerButton.tag=SUBCONTRACTOR_BUTTON_TAG; 
     assignREsCellElementlabel.tag=ELEMENT_LABEL_TAG; 
     assignREsCellDetailLabel.tag=DETAIL_LABEL_TAG; 
     assignResImageView.tag=BG_IMAGEVIEW_TAG; 
     tradeTextView.tag=TRADE_TEXTVIEW_TAG; 
     subContractorTextView.tag=SUBCONTRACTOR_TEXTVIEW_TAG; 
     tradeSelectedNameTextView.tag=TRADE_NAME_TEXTVIEW_TAG; 
     subContractorSelectedNameTextView.tag=SUBCONTRACTOR_NAME_TEXTVIEW_TAG; 
     tradeSpinnerBackgroundView.tag=133; 
     subcontractorSpinnerView.tag=134; 
    } 

    //SetTag 

    assignREsCellElementlabel=(UILabel*)[cell viewWithTag:ELEMENT_LABEL_TAG]; 
    assignResCellViewButton=(UIButton*)[cell viewWithTag:VIEW_BUTTON_TAG]; 
    assignResCellNoteButton=(UIButton*)[cell viewWithTag:NOTE_BUTTON_TAG]; 
    assignREsCellDetailLabel=(UILabel*)[cell viewWithTag:DETAIL_LABEL_TAG]; 
    tradeSpinnerButton=(UIButton*)[cell viewWithTag:TRADE_SPINNER_BUTTON_TAG]; 
    subContractorSpinnerButton=(UIButton*)[cell viewWithTag:SUBCONTRACTOR_BUTTON_TAG]; 
    subContractorTextView=(UITextView*)[cell viewWithTag:SUBCONTRACTOR_TEXTVIEW_TAG]; 
    assignResImageView=(UIImageView*)[cell viewWithTag:BG_IMAGEVIEW_TAG]; 
    tradeTextView=(UITextView*)[cell viewWithTag:TRADE_TEXTVIEW_TAG]; 
    subContractorSelectedNameTextView=(UITextView*)[cell viewWithTag:SUBCONTRACTOR_NAME_TEXTVIEW_TAG]; 
    tradeSelectedNameTextView=(UITextView*)[cell viewWithTag:TRADE_NAME_TEXTVIEW_TAG]; 
    tradeSpinnerBackgroundView=(UITextView*)[cell viewWithTag:133]; 
    subcontractorSpinnerView=(UITextView*)[cell viewWithTag:134]; 
    //Set Text 
    assignREsCellElementlabel.text=defect.defectElement.name; 
    assignREsCellDetailLabel.text=defect.defectItem.name; 
    //set viewButton image on the basis of defectPhoto availability 





    assignResCellViewButton.titleLabel.text=[NSString stringWithFormat:@"%d",indexPath.row]; 
    assignResCellNoteButton.titleLabel.text=[NSString stringWithFormat:@"%d",indexPath.row]; 
    if(defect.defectPhoto && defect.defectPhoto.location && [StringUtil isValid:defect.defectPhoto.location]){ 

     [assignResCellViewButton setImage:greenLenseImage forState:UIControlStateNormal]; 

    }else{ 
     [assignResCellViewButton setImage:lenceImage forState:UIControlStateNormal]; 
    } 


    //set note button image on the basis of comment availability 

    if (defect.hasComments){ 
     [assignResCellNoteButton setImage:noteExistImage forState:UIControlStateNormal]; 

    } else { 
     [assignResCellNoteButton setImage:noteNotExistImage forState:UIControlStateNormal]; 
    } 


    defect.tradeTextView=tradeTextView; 

    defect.subContractorTextView=subContractorTextView; 

    //Show Trade 
    [self decideTradeToBePlaced:defect :row]; 

    //Show SubContractor 
    [self decideSubContractorToBePlaced:defect :row]; 
    tradeSpinnerButton.titleLabel.text=[NSString stringWithFormat:@"%d",indexPath.row]; 
    subContractorSpinnerButton.titleLabel.text=[NSString stringWithFormat:@"%d",indexPath.row]; 
    //subContractorSpinnerButton.tag=indexPath.row; 
    //Set Cell Background(alternate white and gray) 

    // defect.tableCell= assignResponsibilityTableCustomCell; 

    if(indexPath.row % 2 ==0){ 

     [assignResImageView setBackgroundColor:[UIColor whiteColor]]; 

    }else{ 

     [assignResImageView setBackgroundColor:[UIColor lightGrayColor]]; 
    } 

    return cell; 
} 

回答

0

你有一个内存分配/释放问题。

使用工具配置您的应用并选择“僵尸”工具。这将允许您确切地确定这种内存滥用的发生地点。

此外,仪器将让你看到完整的保留/释放循环有问题的对象 - 通常这是很简单的跟踪这些下来,一旦你得到了这个数据。

如果你仍然需要一些更多的帮助,一定要在“学习工具”看WWDC 2012届409。