i am using uitableview and i am facing a problem in cellforrow delegate i use this code
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"mycell";
CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];
cell = (CustomCell *)[topLevelObjects objectAtIndex:2];
cell.btn_Selected.hidden=YES;
cell.btn_Selected.tag=indexPath.row+1;
[array_btnContainer addObject:cell.btn_Selected];
}
my problem is that when i run app it load my table view and create cells but when i scroll my table view it creates one more cell why ????
it must reuse the already created cell and not to enter (cell==nil) block but when ever i scroll it creates one cell and reuse other cell why???? i am stuck
This can be achieved via following these steps
Create a reference of your CustomCell in .h file which you are using to show the tableview whatever it is lets called it ShowTableView.h.
IBOutlet CustomCell *cell;
Go to CustomCell.xib and select the fileowner then set the class property as ShowTableView.
Attached the cell reference with the CustomCell
Select the CustomCell and then set property Identifier value with mycell
Now go to your ShowTableView.m file and cellForRowAtIndexPath method place this code:
Now it will reuse your previous cells