作者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://www.ptt.cc/bbs/MacDev/M.1398156851.A.CE7.html
→ tom19830924:隔空抓藥 init方法應該改用 initWithStyle:reuseIdent 04/22 17:49
→ tom19830924:ifier那個方法 另外viewDidLoad已經註冊Cell 不用再 04/22 17:49
→ tom19830924:cellForRowAtIndexPath重新init 只要這樣就好了 04/22 17:50
→ tom19830924:CustomCell *cell = [tableView dequeueReusableCellW 04/22 17:51
→ tom19830924:ithIdentifier:@"cellID"]; 04/22 17:51
→ psheaven:謝謝~~~~ 04/23 16:24