简体   繁体   中英

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.

@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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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