2011-08-28 5 views
0

편집 : 좋아, 그래서 원래의 문제를 해결하는 방법을 알아 냈습니다,하지만 이것이 최선의 방법인지 모르겠습니다./경우 UITableViewCell에서 속성을 해제하려면

@property (nonatomic, retain) IBOutlet UILabel *levelLabel; 

이는 IB에 연결 :

나의 새로운 질문은, 내가 헤더에 다음과 같은 속성 선언에있는 UITableViewCell의 하위 클래스를 말한다. dealloc에서 이것을 공개하지 않고 전혀 해제하지 않습니까? 이것은 exc_bad_access 오류를주지 않고도 작동하도록 알아낼 수있는 유일한 방법입니다. 이전에는 tableviewcell이 화면을 벗어 났지만 dealloc을 호출했지만 여전히 필요했습니다. 어디에서 물건을 풀어 주나요, 아니면 제가 그걸 처리합니까?

원래 제목 : UITableView 및 exc_bad_access의 메모리 누수 좋아, 혼란스러워. 나는이 튜토리얼 온라인과 함께 맞춤 UITableViewCells를 만들고 있었다. 나는 하나를 만들었고, 튜토리얼이 말한 것처럼 모든 것을했습니다. 내 UITableViewCell 하위 클래스에는 3 개의 UILabels 및 3 개의 UIButton이 포함되어 있으며 모두 속성으로 정의되어 있고 IB로 연결되어 있습니다. 단추를 눌렀을 때를 알 필요가 있고 텍스트를 변경할 수 있어야하기 때문에 클래스에 사용할 수있게해야합니다. 앱을 실행하면 스크롤이 시작되고 몇 초 후 exc_bad_access가 메인 (콘솔에 출력되지 않음)에서 충돌합니다. 하지만 NSZombieEnabled가 설치된 기기에서 앱을 실행할 때 충돌이 전혀 발생하지 않고 잘 돌아갑니다. 그러나 악기는 할당을 보여주기 때문에 특히 스크롤 할 때 매우 빨리 올라갈 수 있습니다. 나는 이것이 전부 할당인지 또는 이들이 공개되는지는 알지 못하지만 여전히 너무 빨라 보인다. 여기

는 PointCoordinatesCell.h (내 사용자 지정 셀)입니다 :

#import <UIKit/UIKit.h> 

@interface PointCoordinatesCell : UITableViewCell 


@property (nonatomic, retain) IBOutlet UILabel *levelLabelLabel; 
@property (nonatomic, retain) IBOutlet UILabel *levelLabel; 
@property (nonatomic, retain) IBOutlet UILabel *levelDescriptionLabel; 
@property (nonatomic, retain) IBOutlet UIButton *beginningButton; 
@property (nonatomic, retain) IBOutlet UIButton *developingButton; 
@property (nonatomic, retain) IBOutlet UIButton *secureButton; 

@end 

PointCoordinatesCell.m :

#import "PointCoordinatesCell.h" 

@implementation PointCoordinatesCell 
@synthesize levelLabel, levelLabelLabel, levelDescriptionLabel, beginningButton, developingButton, secureButton; 

- (void)dealloc{ 
    [super dealloc]; 
    [levelLabel release]; 
    [levelLabelLabel release]; 
    [levelDescriptionLabel release]; 
    [beginningButton release]; 
    [developingButton release]; 
    [secureButton release]; 
} 

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier 
{ 
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; 
    if (self) { 
     // Initialization code 
    } 
    return self; 
} 

- (void)setSelected:(BOOL)selected animated:(BOOL)animated 
{ 
    [super setSelected:selected animated:animated]; 

    // Configure the view for the selected state 
} 

@end 

RootViewController.h는 클래스 선언 및 표준 수입 이외의 그것에는 아무 상관이 없습니다. 정의 된 변수 또는 메소드가 없습니다. UITableViewController 하위 클래스입니다.

RootViewController.m : 라벨을 공개하지에

#import "RootViewController.h" 
#import "StatesAppDelegate.h" 
#import "PointCoordinatesCell.h" 

@implementation RootViewController 

- (void)viewDidLoad { 
    [super viewDidLoad]; 


    // Uncomment the following line to display an Edit button in the navigation bar for this view controller. 
    // self.navigationItem.rightBarButtonItem = self.editButtonItem; 
} 

- (void)didReceiveMemoryWarning { 
    [super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview 
    // Release anything that's not essential, such as cached data 
} 

#pragma mark Table view methods 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
    return 1; 
} 


// Customize the number of rows in the table view. 
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    return 50; 
} 


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath; 
{ 
    return 293; 
} 

// Customize the appearance of table view cells. 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString *CellIdentifier = @"PointCoordinatesCell"; 

    PointCoordinatesCell *cell = (PointCoordinatesCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 

     NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"PointCoordinatesCell" owner:self options:nil]; 

     for (id currentObject in topLevelObjects){ 
      if ([currentObject isKindOfClass:[UITableViewCell class]]){ 
       cell = (PointCoordinatesCell *) currentObject; 
       break; 
      } 
     } 
    } 

    //cell.capitalLabel.text = [capitals objectAtIndex:indexPath.row]; 
    //cell.stateLabel.text = [states objectAtIndex:indexPath.row]; 

    return cell; 
} 


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    // Navigation logic may go here. Create and push another view controller. 
    // AnotherViewController *anotherViewController = [[AnotherViewController alloc] initWithNibName:@"AnotherView" bundle:nil]; 
    // [self.navigationController pushViewController:anotherViewController]; 
    // [anotherViewController release]; 
} 



- (void)dealloc { 
    [super dealloc]; 
} 


@end 

답변

0

당신이 당신의 cellForRowAtIndexPath 방법 몇 가지 복잡한 캐스팅을하고있는 것 같다 ... 말할 수 있습니다. 나는 이것이 필요하다고 생각하지 않는다. 클래스 UITableViewCell의 개체를 확인한 다음이를 사용자 지정 셀로 캐스팅하는 것은 논리적으로 보이지 않습니다. 펜촉의 셀은 이미 사용자 정의 셀이어야합니다.

Apple 샘플에서 셀로드는 훨씬 간단합니다. 이 작업을 수행 한 다음 뷰 컨트롤러에 IBOutlet로 정의 셀을 연결 :

CustomCell *cell = (CustomCell *) [aTableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) { 
    [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil]; 
    cell = customTableViewCell; 
    self.customTableViewCell = nil; 
    // etc. 
} 
0

아니, 괜찮 없습니다. '보유'지정자로 속성을 선언했습니다. 즉 적어도 dealloc에서 해제해야합니다 (안전한 방법은 self. levelLabel = nil;).

개체를 놓지 않으면 메모리 누수가 발생하여 스크롤하는 동안 메모리 사용량이 증가합니다. 우리가 당신을 도울 수 있도록 EXC_BAD_ACCESS 오류가 발생하는 경우 당신은해야합니다

+0

그는 최대한 멀리 볼 수 dealloc''에서 라벨을 출시 할 예정이다 .... – Mundi

관련 문제