无法设置textlabel单元格

时间:2011-04-02 09:01:17

标签: iphone ios ios4 sdk

这是我的代码

@property (nonatomic,retain) NSMutableArray *category;

@synthesize category;

NSString * path = [[NSBundle mainBundle] pathForResource:@"categorylist" ofType:@"txt"];
    NSString * content = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:NULL];
    self.category = [NSMutableArray arrayWithArray:[content componentsSeparatedByString:@"\n"]];
    [content release];

并且此处有错误

cell.textLabel.text = [category objectAtIndex:[indexPath row]];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    return cell;

我是新手。所以请帮我找出解决方案。

v v v 来自许多帮助这是最终解决方案代码。

@property (nonatomic,retain) NSMutableArray *category;

@synthesize category;

NSString * path = [[NSBundle mainBundle] pathForResource:@"categorylist" ofType:@"txt"];
    NSString * content = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:NULL];
    self.category = [NSMutableArray arrayWithArray:[content componentsSeparatedByString:@"\n"]];

在这里

cell.textLabel.text = [NSString stringWithFormat:@“%@”,[self.category objectAtIndex:indexPath.row]];

2 个答案:

答案 0 :(得分:1)

不发布内容。如果您未使用allocnewretaincopy,则不允许发布。

您应该再次阅读Memory Management Programming Guide

答案 1 :(得分:0)

从你的代码中,一切都是正确的......可能是以下事情背后的错误

1.通过打印

检查您的类别数组是否包含值
NSLog(@"%@", category);

2.Did你告诉你的数组计数为numberOfRowsInSection函数

3.Did你在dealloc

中释放类别数组的内存

4.Did U为tableview ???

设置datasource

最好的问候

相关问题