大家好,我有一个大问题。我正在开发一款iPad应用程序。在这里我已经在UITableView中重用了表视图单元格。早些时候我没有重复使用细胞,它工作但很慢。为了提高性能我现在已经破坏了单元格它非常快但是当我滚动很多次或者速度然后* EXC_BAD_ACCESS *发生了以下消息:
-[CALayer retain]: message sent to deallocated instance 0x5aba7b0
我找到了正在发布的实际IBOutlet。它是UIImageView。之前同样的问题是在单元格中有一个UIButton。我用保留属性声明它然后它被解决了。现在,如果我声明imageview保留它的工作,但..prob现在是我需要2种类型的imageViews根据单元格奇数或偶数的位置。现在它在..continue 3,2,4 ......中显示相同的图像视图。我有问题,请帮助遵循代码:还有一件事我加载了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 :(得分:0)
你有内存分配/释放问题。
使用乐器配置您的应用,然后选择“Zombies”乐器。这样您就可以准确识别内存滥用的确切位置。
此外,Instruments还允许您查看相关对象的完整保留/发布周期 - 通常,一旦获得此数据,就可以非常简单地跟踪这些对象。
如果您还需要更多帮助,请务必观看有关“学习乐器”的WWDC 2012会话409.