作者leetzuwen (蚊子)
看板MacDev
標題[問題] 新手請問UItableView的用法
時間Tue Oct 6 02:06:10 2009
之前沒寫過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
1F:→ uranusjr:最後面改用 [NSString stringWithString:@"test"] ? 10/06 02:21
2F:→ uranusjr:唔, 我把你的 method 拿去複製貼上一個全新的 Navigation 10/06 02:28
3F:→ uranusjr:based Application 執行無誤...你可能要檢查其他的地方 10/06 02:28
4F:→ leetzuwen:我不是用navigation而是用一個UItableViewController 10/06 02:37
5F:→ leetzuwen:問題是出在這邊嗎? 10/06 02:37
6F:推 aecho:initWithFrame在 OS 3.0之後就沒在用了~~ 10/06 07:57
7F:→ aecho:改用 initWithStyle 10/06 07:57
8F:推 aecho:啊~~ 我看到cell在alloc時,多了一個autorelease... 10/07 07:14
9F:→ aecho:這邊要加autorelease嗎?印象中我都沒加過 XDD 10/07 07:15
10F:→ zonble:要加 10/07 23:55
11F:→ zonble:不加會 memory leak 10/07 23:55