Reputation:
I taken a custom cell and i am not reusing the identifier over there. I am using the identifier in the table view where i am using that custom cells. But when i run my application and entering the data in textfield my data getting erased when i scroll the view.and My cell are not reusing that data.Can any one help me out in this thing. Thanks!
Custom cell code
-(UITableViewCell *)returnCellForEach:(UITableView *)tableView
{
[[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];
myLabel = (UILabel *)[customCell.contentView viewWithTag:10];
return customCell;
}
Table view 'cellForRowAtIndexPath' code
static NSString *CellIdentifier = @"Cell";
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"Hello"] autorelease];
}
whats mistake i this thing. Thanks!
Upvotes: 0
Views: 208
Reputation: 662
I dont get your question actually, But I have done like following :
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = (CustomCell *)[[[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil] objectAtIndex:0];
}
myLabel = (UILabel *)[customCell.contentView viewWithTag:10];
//myLabel = cell.labelWithTag10;
myLable.text = @"Text";
And It works fine for me;
Upvotes: 0
Reputation: 2862
Cells should not be used to store your data. If the user enters something in the edit field, you need to copy the content to e.g. a member variable in your view controller. If the cell is scrolled out of view, it is either destroyed, or it MIGHT be kept for reuse. Either way, you can not rely on that edit field to exist anymore.
Upvotes: 1