0

みなさん、こんにちは。私は大きな問題を抱えています。私は iPad アプリを開発しています。これで、UITableView のテーブル ビュー セルを再利用しました。以前はセルを再利用していませんでしたが、機能していましたが非常に遅かったです。パフォーマンスを向上させるためにセルを使用しましたが、非常に高速ですが、何度もスクロールしたり、高速でスクロールしたりすると、*EXC_BAD_ACCESS* が次のメッセージで発生しました。

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

リリースされている実際の IBOutlet を見つけました。UIImageView です。同じ問題がセル内の UIButton で発生する前に。保持プロパティで宣言したところ、解決されました。imageviewを保持すると宣言すると機能しますが、セルの奇数または偶数の位置に応じて2種類のimageViewが必要になることが問題です。現在、同じイメージビューが ..continue 3,2,4..cells に表示されていません。私は問題に苦しんでいます。コードに従うのを手伝ってください: 3 種類のセルをロードするもう 1 つのことなので、cellIdientifier を Defect オブジェクトに保存しました。

#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;
}
4

1 に答える 1

0

メモリの割り当て/割り当て解除の問題があります。

Instrumentsを使用してアプリのプロファイルを作成し、「Zombies」インストゥルメントを選択します。これにより、このメモリの誤用が発生している場所を正確に特定できます。

さらに、Instrumentsを使用すると、問題のオブジェクトの完全な保持/解放サイクルを確認できます。通常、このデータを取得したら、これらを追跡するのは非常に簡単です。

それでもサポートが必要な場合は、「LearningInstruments」のWWDC2012セッション409を必ずご覧ください。

于 2012-11-23T22:10:32.410 に答える