Reputation: 77
I have a problem with some segmented controls: I have a tableview with 10 cells and all cells have one segmented control.
Now my problem: If I change the selected index of a segmented control and scroll up or down, the selected index of some segmented controls are change.
Has anyone an idea whats false?
//Edit:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier;
CellIdentifier = @"editCell";
cellList[indexPath.row-1] = [[MSEditCardCell alloc] init];
cellList[indexPath.row-1] = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
return cellList[indexPath.row-1];
}
Upvotes: 0
Views: 225
Reputation: 131491
As Durican says, this is a problem with cell reuse. You need to set up a data model that stores the information you are presenting in each cell. When the user changes the selected segment in a given cell, you need to respond to that change by updating that bit of information in your model.
Then, in your cellForRowAtIndexPath method, you need to fetch the appropriate entry from your model and use the information to fully configure the new cell, including setting the state of the segmented control for that cell.
This is basic table view stuff, and something most people struggle with when they first start using table views.
Upvotes: 1
Reputation: 1337
It's is because the cells are being reused when you scroll. Just add a iVar or a property for the cell (Boolean), and everytime you are configuring your cell in cellForRowAtIndexPath, make sure you set the segmentedControl accordingly to the bool you are setting
Upvotes: 0