[問題] 新手請問UItableView的用法

看板MacDev作者 (蚊子)時間15年前 (2009/10/06 02:06), 編輯推噓2(209)
留言11則, 4人參與, 最新討論串1/2 (看更多)
之前沒寫過UItableView, 這幾天第一次嘗試的時候卻一直碰到瓶頸。 照著網路上的資料一步步實作卻一直無法成功顯示出text, 在網路上找了好久仍然找不到原因及方法, 以下是我的程式碼 #import "NextViewController.h" @implementation NextViewController - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:\ (NSIndexPath *)indexPath { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"any\ -cell"]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentif\ ier:@"any-cell"] autorelease]; } cell.textLabel.text = @"test"; return cell; } @end 一開始我是使用cell.setText來處理,但是OS 3.0後好像就不能使用了, 於是改用cell.textLable.text,可以執行但是卻無法顯示, 一直無法找出原因, 可以請提醒我哪個部份的觀念有錯誤嗎? 謝謝。 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.32.236.106

10/06 02:21, , 1F
最後面改用 [NSString stringWithString:@"test"] ?
10/06 02:21, 1F

10/06 02:28, , 2F
唔, 我把你的 method 拿去複製貼上一個全新的 Navigation
10/06 02:28, 2F

10/06 02:28, , 3F
based Application 執行無誤...你可能要檢查其他的地方
10/06 02:28, 3F

10/06 02:37, , 4F
我不是用navigation而是用一個UItableViewController
10/06 02:37, 4F

10/06 02:37, , 5F
問題是出在這邊嗎?
10/06 02:37, 5F

10/06 07:57, , 6F
initWithFrame在 OS 3.0之後就沒在用了~~
10/06 07:57, 6F

10/06 07:57, , 7F
改用 initWithStyle
10/06 07:57, 7F

10/07 07:14, , 8F
啊~~ 我看到cell在alloc時,多了一個autorelease...
10/07 07:14, 8F

10/07 07:15, , 9F
這邊要加autorelease嗎?印象中我都沒加過 XDD
10/07 07:15, 9F

10/07 23:55, , 10F
要加
10/07 23:55, 10F

10/07 23:55, , 11F
不加會 memory leak
10/07 23:55, 11F
文章代碼(AID): #1AoZMLfl (MacDev)
文章代碼(AID): #1AoZMLfl (MacDev)