分段的UITableView在accesoryview中提供了意外的行为
||
我有一个包含三个部分的UITableView。
第1节有一个单元格,其accesoryview中包含UISwitch
failAtLaunch
第2部分包含failSounds数组中的项目,并为所选项目(在此情况下为声音)具有单个复选标记
第3节包含一个按钮。
您可以在下面看到我如何配置单元。
问题在于该表给出了奇怪的行为。每当我在表格视图中上下移动,单元格进出视图时,第2节中的某些单元格都会在其accesoryview中获得UISwitchfailAtLaunch
。
谁能帮我理解为什么会这样吗?
提前致谢!
- (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;
}
}
没有找到相关结果
已邀请:
2 个回复
亨尖玛次酥
舜辉