Reputation: 382
Shown below is the code I am using to create the cell. The cell is not being reused. Every time the cell==nil
is becoming true.
I am setting the identifier correctly in the xib. Please help me.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
SRCourseListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
if (cell == nil) {
NSArray *nib=[[NSBundle mainBundle]loadNibNamed:@"SRCourseListCell" owner:self options:nil];
cell=[nib objectAtIndex:0];
}
return cell;
}
Upvotes: 1
Views: 1703
Reputation: 2158
Using the following code to initialize:
YourTableViewCell *cel = [[YourTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"identifier"];
Upvotes: -1
Reputation: 5183
In you "SRCourseListCell.xib", go to the Attributes Inspector and set "SRCourseListCell" for Identifier.
Replace below modified code with your exciting one.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { SRCourseListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SRCourseListCell"]; if (cell == nil) { NSArray *nib=[[NSBundle mainBundle]loadNibNamed:@"SRCourseListCell" owner:self options:nil]; cell=[nib objectAtIndex:0]; } return cell; }
When calling xib for custom cell, make sure that Identifier for the xib must be same as you are using with:
[tableView dequeueReusableCellWithIdentifier:@"SRCourseListCell"]
Upvotes: 1
Reputation: 52227
in your SRCourseListCell, add
- (NSString *) reuseIdentifier {
return @"cell";
}
or (as you are using nibs maybe the better solution), set the identifier to "cell" in the inspector.
Upvotes: 2