作者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