The problem is from the dequeueReusableCellWithIdentifier: use different static strings for each type of cell.
Up vote 0 down vote favorite 1 share g+ share fb share tw.
I've got a UITableView containing three sections. Section 1 has one cell containing a UISwitch failAtLaunch in its accesoryview Section 2 contains the items from the failSounds array and has a singular checkmark for the selected item (sound in this case) Section 3 contains a button. You can see below how I configure the cells.. The problem is that the table gives strange behaviour.
Whenever I scroll up and down the tableview, with cells moving in and out of view, some cells in section 2 get the UISwitch failAtLaunchin their accesoryview. Can anyone help me understand why this is? Thanks in advance!
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { //....blablabla... // Configure the cell... NSUserDefaults *prefs = NSUserDefaults standardUserDefaults; NSString *theSound = prefs objectForKey:@"pickedFailSound"; NSUInteger index = failSounds indexOfObject:theSound; if (indexPath. Section == 0){ failAtLaunch = UISwitch alloc initWithFrame:CGRectMake(200, 7, 100, 30) autorelease; cell addSubview:failAtLaunch; cell. AccessoryView = failAtLaunch; cell.
SelectionStyle = UITableViewCellSelectionStyleNone; NSUserDefaults *prefs = NSUserDefaults standardUserDefaults; if(!prefs boolForKey:@"failAtLaunch") { failAtLaunch setOn:NO animated:NO; } else { failAtLaunch setOn:YES animated:NO; } (UISwitch *)cell. AccessoryView addTarget:self action:@selector(setIt) forControlEvents:UIControlEventValueChanged; cell.textLabel. Text = @"Instafail"; return cell; } else if (indexPath.
Section == 1) { NSString *cellTitle = failSounds objectAtIndex:indexPath. Row; cell.textLabel. Text = cellTitle; if (indexPath.
Row == index) { cell. AccessoryType = UITableViewCellAccessoryCheckmark; } return cell; } else { cell = tableView dequeueReusableCellWithIdentifier:@"buttonCell"; if (cell == nil) { cell = UITableViewCell alloc initWithFrame:CGRectZero reuseIdentifier:@"buttonCell" autorelease; } cell.textLabel. Text = @"Hold to record fail sound"; UIButton *btn = UIButton buttonWithType:UIButtonTypeRoundedRect; btn.
Frame = CGRectMake(230.0f, 4.0f, 60.0f, 36.0f); btn setTitle:@"OK" forState:UIControlStateNormal; btn setTitle:@"OK" forState:UIControlStateSelected; btn addTarget:self action:@selector(recordAudio) forControlEvents:UIControlEventTouchDown; btn addTarget:self action:@selector(stop) forControlEvents:UIControlEventTouchUpInside; cell. ContentView addSubview:btn; return cell; } } iphone cocoa-touch uitableview accessoryview link|improve this question asked Apr 14 '11 at 13:14Thomas K469315 100% accept rate.
Great! That fixed it. – Thomas K Apr 14 '11 at 14:06.
It's your blah blah blah section. I think you are probably using the same reuse-identifier for all 3 types of rows, and not clearing them out prior to re-use. So when you instantiate a new tableViewCell, you need to switch on section and give each one a unique identifier.
What I usually do is tag every view that I add to a cell with a tag like "CLEAR_ME_OUT" that is defined as some large arbitrary number. Then when I re-use a cell, I loop through the sub-views and removeFromSuperview all cells with that tag. That way it's nice a clean for re-use.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.