[請益] 詢問TableViewCell相關問題

看板MacDev作者 (唄咩)時間11年前 (2014/04/22 16:54), 編輯推噓0(006)
留言6則, 2人參與, 最新討論串1/1
請問如果要讓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

04/22 17:49, , 1F
隔空抓藥 init方法應該改用 initWithStyle:reuseIdent
04/22 17:49, 1F

04/22 17:49, , 2F
ifier那個方法 另外viewDidLoad已經註冊Cell 不用再
04/22 17:49, 2F

04/22 17:50, , 3F
cellForRowAtIndexPath重新init 只要這樣就好了
04/22 17:50, 3F

04/22 17:51, , 4F
CustomCell *cell = [tableView dequeueReusableCellW
04/22 17:51, 4F

04/22 17:51, , 5F
ithIdentifier:@"cellID"];
04/22 17:51, 5F

04/23 16:24, , 6F
謝謝~~~~
04/23 16:24, 6F
文章代碼(AID): #1JLYuppd (MacDev)
文章代碼(AID): #1JLYuppd (MacDev)