大家好,我有一个大问题。我正在开发一个 iPad 应用程序。在此,我在 UITableView 中重用了表格视图单元格。早些时候我没有重复使用这些单元格,它正在工作,但速度很慢。为了提高性能,我现在使用了单元格,它非常快,但是当我滚动多次或快速滚动时,*EXC_BAD_ACCESS* 出现以下消息:
-[CALayer retain]: message sent to deallocated instance 0x5aba7b0
我找到了正在发布的实际 IBOutlet 。它是 UIImageView 。在此之前,同样的问题是单元格中的 UIButton。我用保留属性声明了它,然后它被解决了。现在,如果我声明 imageview 保留它可以工作,但是..prob 现在是根据单元格奇数或偶数的位置我需要 2 种类型的 imageViews。现在它在..continue 3,2,4..cells 中显示相同的图像视图未修复。我正在努力解决问题,请帮助遵循代码:另一件事我加载了 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;
}