简体   繁体   English

无法设置文字标签单元格

[英]Can't set textlabel cell

Here is my code 这是我的代码

@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];

and It has error here 而且这里有错误

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

I'm newbie. 我是新手。 so Please help me find out the solution please. 所以请帮我找出解决方案。

vvv From many help This is finalize solution code. vvv来自许多帮助这是最终确定解决方案的代码。

@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"]];

and here 和这里

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

don't release content. 不要发布内容。 If you didn't use alloc , new , retain or copy you are not allowed to release. 如果您不使用allocnewretaincopy ,则不允许释放。

You should read the Memory Management Programming Guide again 您应该再次阅读《 内存管理编程指南》

From your code everything is correct ..may be bug behind the following thing 从您的代码一切都正确..可能是以下内容的错误

1.Check your category array wethere it contain value by printing 1.检查您的类别数组是否湿润,其中包含打印值

NSLog(@"%@", category);

2.Did u inform ur array count to numberOfRowsInSection function 2.您是否将数组计数告知numberOfRowsInSection函数

3.Did u release category array's memory in dealloc 3.您是否在dealloc释放了类别数组的内存

4.Did U set datasource for tableview??? 4.您是否为tableview设置了datasource ???

Best Regards 最好的祝福

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM