Reusing IB created UITableViewCells
Hi,
I have created an UITableViewCell in IB which contains two UILabels. In the controller I have created Outlets for the cell as well as the labels. Now I want to reuse this cell within the table view (see code below). Unfortunatly it does not work as expected. The cell appears only once and two empty cells above it. What's wrong with my code? I guess I missunderstand the dequeueing mechanism.
Does anyone have a hint?
Best regards,
Michael
* Code *
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"xxx"];
if(cell == nil) {
cell = myCell // myCell is an Outlet - connected in IB
}
// label1 and label2 are also Outlets
label1.text = [NSString stringWithFormat:@"%d", indexPath.row];
label2.text = [NSString stringWithFormat:@"%d", indexPath.section];
return cell;
}
I have created an UITableViewCell in IB which contains two UILabels. In the controller I have created Outlets for the cell as well as the labels. Now I want to reuse this cell within the table view (see code below). Unfortunatly it does not work as expected. The cell appears only once and two empty cells above it. What's wrong with my code? I guess I missunderstand the dequeueing mechanism.
Does anyone have a hint?
Best regards,
Michael
* Code *
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"xxx"];
if(cell == nil) {
cell = myCell // myCell is an Outlet - connected in IB
}
// label1 and label2 are also Outlets
label1.text = [NSString stringWithFormat:@"%d", indexPath.row];
label2.text = [NSString stringWithFormat:@"%d", indexPath.section];
return cell;
}