[请益] 询问TableViewCell相关问题

楼主: psheaven (玛尼爱我)   2014-04-22 16:54:08
请问如果要让UITableViewCell可重复使用节省内存,但CellStyle又要是Subtitle应该
要怎么写呢?
问过朋友是说需要另外写一个TableViewCell的Subclass,再override init去修改style
依照我自己找出来的方法执行后ViewCellStyle还是default,希望各位前辈能帮忙指点是
哪里的问题 感激不尽 ><
以下是撷取TableView相关的code
===========
@interface CustomCell : UITableViewCell
@end
@implementation CustomCell
-(id)init
{
self = [super initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:@"cellID"];
return self;
}
@end
===========
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
CustomCell* c = [[CustomCell alloc]init];
c = [tableView dequeueReusableCellWithIdentifier:@"cellID"];
return c;
}
===========
-(void) viewDidLoad
{
[self.tableView registerClass: [CustomCell class] forCellReuseIdentifier:
@"cellID"];
}
作者: tom19830924 (Tom Hsu)   2014-04-22 17:49:00
隔空抓药 init方法应该改用 initWithStyle:reuseIdentifier那个方法 另外viewDidLoad已经注册Cell 不用再cellForRowAtIndexPath重新init 只要这样就好了CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellID"];
楼主: psheaven (玛尼爱我)   2014-04-23 16:24:00
谢谢~~~~

Links booklink

Contact Us: admin [ a t ] ucptt.com