开发者

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.

v v v From many help This is finalize solution 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"]];

and here

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.

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

NSLog(@"%@", category);

2.Did u inform ur array count to numberOfRowsInSection function

3.Did u release category array's memory in dealloc

4.Did U set datasource for tableview???

Best Regards

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜