-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中的引用对象。我的设置有什么问题?太赫兹。
你究竟在哪里遇到错误? – 2010-05-02 12:41:07
请注意,您有一个单独的错误 - 您只配置单元格,如果它不被重新使用。 – 2010-05-03 13:47:32