I created a sample application that inserts 12 rows into a tableview.And added fine.When I inserted my rows, I don’t want any changes to the text while scrolling through the tableview.So I checked with the indexpath the row has a value of UITableViewCell, if it has values it means return this cell, otherwise we created a new UITableViewCell.
My sample code below
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSLog(@"GlobalCount = %d",GlobalCount);
return GlobalCount;
}
- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *obj = (UITableViewCell*)[tableView cellForRowAtIndexPath:indexPath];
if(obj!=nil)
{
NSLog(@"cell indexpath row = %d",indexPath.row);
NSLog(@"cell text = %d",obj.textLabel.text);
return obj;
}
else {
NSLog(@"obj==nil");
}
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tv dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
if([DataTable count]>0)
cell.textLabel.text = [DataTable objectAtIndex:0];
return cell;
}
What is my goal: I do not want to update any text (or UITableViewCell) for already created rows of the index path (cell). So I can check this in cellForRowAtIndexPath, but it always returns nil.If I haven't missed anything?
I checked this line
UITableViewCell *obj = (UITableViewCell*)[tableView cellForRowAtIndexPath:indexPath];
if(obj!=nil)
Help me with plz?
Thanks in advance...
Tamil