开发者

Why I got a "sent to freed object error"?

开发者 https://www.devze.com 2022-12-29 09:25 出处:网络
I have a Table View, and CharTableController, the CharTableController works like this: .h: #import <Foundation/Foundation.h>

I have a Table View, and CharTableController, the CharTableController works like this:

.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

The .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; 
    [a开发者_StackOverflow社区rray 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

And I Use the IB to link the TableView's dataSource and delegate to the CharTableController. In the CharTableController's view is the TableView in IB obviously. Reference Object in dataSource > TableView and delegate > TableView. What's wrong with my setting? thz.


How is listData filled ? Maybe you add objects in the Array, then somewhere, these objects are released. So listData reference a not more existing object.

Put a breakpoint in your object dealloc method to see when is being released and try to enable NSZombie.

Thierry

0

精彩评论

暂无评论...
验证码 换一张
取 消