Reputation: 441
I have created a xib file and then created a class of tableViewCell. I have attached photos of how I have attached the outlets to the file. I am trying to assign values to the cells that are made during the tableview cell creation but the cells keep appearing blank once the app runs. Here are a few screenshots of my code and the xib file.
Any help would be massively appreciated.
Upvotes: 0
Views: 603
Reputation: 39
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *cellidenfier=@"cell";
League *cell=[tableView dequeueReusableCellWithIdentifier:cellidenfier];
if (cell==nil) {
cell=[[[NSBundle mainBundle]loadNibNamed:@"League" owner:self options:nil]objectAtIndex:0];
}
return cell;
}
Please make sure that file owner is has class NSObject and you custom cell had class of ur classname. Make a outlet from your custom class not with fileowner...
Upvotes: 0
Reputation: 122
put this code which is registering nib for you in ViewDidLoad
UINib *nib = [UINib nibWithNibName:@"LeagueCell" bundle:nil];
[self.tableView registerNib:nib forCellReuseIdentifier:@"LeagueCellCellIdentifier"];
Now , in CellForRowAtIndexPath
LeagueCell *pnCell = [tableView dequeueReusableCellWithIdentifier:@"LeagueCellCellIdentifier"];
return pnCell;
Note: Use same CellIdentifier in CellForRowAtIndexPath
which you given in ViewDidLoad
Upvotes: 0
Reputation: 3506
Delete the line cell=[[LeagueCell alloc] init];
and change the cell initialisation as follows:
cell = [[NSBundle mainBundle] loadNibNamed:@"LeagueCell" owner:self options:nil] objectAtIndex:0]
Upvotes: 0
Reputation: 392
Try setting tags to the labels
UILabel *name = (UILabel *)[cell viewWithTag:100];
UILabel *position = (UILabel *)[cell viewWithTag:101];
UILabel *score = (UILabel *)[cell viewWithTag:102];
cell.name = [currentObject valueForKey:@"username"];
//rest of the code similarly
Also put
cell = [[LeagueCell alloc] init];
inside
if (cell == nil) {
cell = [[LeagueCell alloc] init];
}
Upvotes: 0
Reputation: 4254
You are dequeing a cell and then instantiating it again. Just remove the line where it says cell = [[LeagueCell alloc] init];
Upvotes: 2