0
用我的表視圖的數據源方法的代碼波紋管(...的cellForRowAtIndexPath:)我創造UISwitch在只有某些細胞爲用戶設置查看進入一個酥料餅的視圖。UISwitch被添加到錯誤和隨機單元格中?
的是,當我向上和向下滾動視圖開關的正在增加,並從我沒有具體說明應該在他們UISwitch隨機池中取出由於某種原因,但是工作的開關。
我在這裏做錯了什麼?
這是我的一些代碼:
if (section == 0) {
if (row == 0) {
cell.textLabel.text = @"Units";
}
if (row == 1) {
cell.textLabel.text = @"Prefered System";
}
if (row == 2) {
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.textLabel.text = @"Lock System";
UISwitch *switch1 = [[UISwitch alloc] initWithFrame:switchFrame];
if ([defaults boolForKey:kLockSystem]) {
[switch1 setOn:YES animated:NO];
}
else {
[switch1 setOn:NO animated:NO];
}
[switch1 addTarget:self action:@selector(switchToggled:) forControlEvents:UIControlEventValueChanged];
switch1.tag = 1;
cell.accessoryView = switch1;
[switch1 release];
}
if (row == 3) {
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.textLabel.text = @"Reset On Exit";
UISwitch *switch2 = [[UISwitch alloc] initWithFrame:switchFrame];
if ([defaults boolForKey:kResetOnExit]) {
[switch2 setOn:YES animated:NO];
}
else {
[switch2 setOn:NO animated:NO];
}
[switch2 addTarget:self action:@selector(switchToggled:) forControlEvents:UIControlEventValueChanged];
switch2.tag = 2;
cell.accessoryView = switch2;
[switch2 release];
}
}
真棒感謝! – cgossain 2011-03-22 02:29:40