I’m trying to show data from a plist file in a custom UITableViewCell.
Here is my rootViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *path = [[NSBundle mainBundle] pathForResource:@"projects" ofType:@"plist"];
projects = [NSArray arrayWithContentsOfFile:path];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
int n = indexPath.row;
for (n=1; n<4; n = n+1) {
NSDictionary *temp = [projects objectAtIndex:indexPath.row];
projectCell.name.text = [temp valueForKey:@"name"];
}
}
return projectCell;
}
The plist file i created only contains 4 dictionaries. And each one of them contains 2 strings. But I only want one of them to be in the cell. (I already created the UITableViewCell file named “ProjectCell”.
I’m just starting, so my question might be really basic. But I spent so much time trying to figure it out.
Could anyone help me out?
EDIT: when i build and run, it always gives me a blank table
EDIT2: Interface of ProjectCell
@interface ProjectCell : UITableViewCell {
IBOutlet UILabel *name;
IBOutlet UITableViewCell *theCell;
}
@property (nonatomic,retain) IBOutlet UILabel *name;
@property (nonatomic,retain) IBOutlet UITableViewCell *theCell;
@end
EDIT3 ProjectCell.m
@implementation ProjectCell
@synthesize name,theCell;
@end
You would be better off adjusting the XIB a bit.
UITableViewCellobject and change its class to ‘ProjectCell’ using the identity inspector.IBOutlet namefrom this object to the existing label.File's Ownerand set it back to NSObject.Now your
ProjectCell.h,and your
ProjectCell.m,And the final changes will be in
tableView:cellForRowAtIndexPath:method,