我已经从UITableView创建了一个派生类,它将包含一些自定义逻辑。但我不知道如何让它填充单元格。 h。UITableView与自定义类
h。文件:
@interface MetricsView : UITableView {
@private
NSMutableArray *_items;
}
@end
m。文件:
@implementation MetricsView
//this gets called
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (self) {
_items = [[NSMutableArray alloc]initWithObjects:@"Name:", nil];
}
return self;
}
//this never gets called??
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
//this never gets called??
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [_items count];
}
//this never gets called??
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *cellIdentifier = @"MetricsViewCell";
MetricsViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
[cell setupWithName:[_items objectAtIndex:0] withData:[_items objectAtIndex:0]];
return cell;
}
@end
我在我的ViewController顶部创建了MetricsView。这里是故事情节的样子:
我需要里面添加ViewController.m一些自定义的初始化代码?
谢谢。
我想我现在明白了,谢谢。 – 2013-05-07 21:38:31
所以现在我收到“的malloc:***错误对象0x75610453:指针被释放没有被分配 ***在malloc_error_break断点设置为调试”后,我打电话的setDataSource。我的MetricsView不再是自定义类,只是默认的UITableView。我是否需要调用metricsView alloc自己? – 2013-05-07 21:50:39
哪来现在的工作,感谢家伙! – 2013-05-07 22:13:31