作者psheaven (呗咩)
看板MacDev
标题[请益] 询问TableViewCell相关问题
时间Tue Apr 22 16:54:08 2014
请问如果要让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"];
}
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 125.227.149.174
※ 文章网址: http://webptt.com/cn.aspx?n=bbs/MacDev/M.1398156851.A.CE7.html
1F:→ tom19830924:隔空抓药 init方法应该改用 initWithStyle:reuseIdent 04/22 17:49
2F:→ tom19830924:ifier那个方法 另外viewDidLoad已经注册Cell 不用再 04/22 17:49
3F:→ tom19830924:cellForRowAtIndexPath重新init 只要这样就好了 04/22 17:50
4F:→ tom19830924:CustomCell *cell = [tableView dequeueReusableCellW 04/22 17:51
5F:→ tom19830924:ithIdentifier:@"cellID"]; 04/22 17:51
6F:→ psheaven:谢谢~~~~ 04/23 16:24