2010-05-02 71 views
-1

我有一個表視圖,並CharTableController的CharTableController是這樣的:爲什麼我得到「發送釋放的對象錯誤」?

.H:

#import <Foundation/Foundation.h> 


@interface CharTableController : UITableViewController <UITableViewDelegate, UITableViewDataSource>{ 
// IBOutlet UILabel *debugLabel; 
    NSArray *listData; 
} 
//@property (nonatomic, retain) IBOutlet UILabel *debugLabel; 
@property (nonatomic, retain) NSArray *listData; 


@end 

的.M:

#import "CharTableController.h" 

@implementation CharTableController 
@synthesize listData; 

- (void)viewDidLoad { 
    NSArray *array = [[NSArray alloc] initWithObjects:@"Sleepy", @"Sneezy", @"Bashful", @"Happy", @"Doc", @"Grumpy", @"Dopey", @"Thorin", @"Dorin", @"Nori", @"Ori", @"Balin", @"Dwalin", @"Fili", @"Kili", @"Oin", @"Gloin", @"Bifur", @"Bofur", @"Bombur", nil]; 
    self.listData = array; 
    [array release]; 

    [super viewDidLoad]; 
} 


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    return [self.listData count]; 
} 

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

    static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: SimpleTableIdentifier]; 

    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] 
      initWithStyle:UITableViewCellStyleDefault 
      reuseIdentifier:SimpleTableIdentifier] autorelease]; 

     NSUInteger row = [indexPath row]; cell.textLabel.text = [listData objectAtIndex:row]; 
    } 
    return cell; 
} 

@end 

我用的是IB來鏈接TableView的dataSource和委託給CharTableController。 在CharTableController的視圖中顯然是IB中的TableView。 dataSource> TableView和委託> TableView中的引用對象。我的設置有什麼問題?太赫茲。

+0

你究竟在哪裏遇到錯誤? – 2010-05-02 12:41:07

+0

請注意,您有一個單獨的錯誤 - 您只配置單元格,如果它不被重新使用。 – 2010-05-03 13:47:32

回答

0

listData如何填充? 也許你在數組中添加對象,然後在某個地方釋放這些對象。 所以listData引用一個不是更多的現有對象。

在你的對象dealloc方法中放置一個斷點來查看何時被釋放並嘗試啓用NSZombie。

Thierry

相關問題