我正在使用 UISwitchs 和 UITextFields 执行此操作...
我已在头文件中将 UISwitch 声明为属性,因为我想在我的类中通过几种不同的方法访问它的值。
我正在使用以下代码将 UISwitch 添加到我的 TableViewCell 之一:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
mySwitch = [[[UISwitch alloc] initWithFrame:CGRectZero] autorelease];
cell.accessoryView = mySwitch;
mySwitch.on = YES;
return cell;
}
事实上,retainCounts 无处不在。将单元格放在屏幕上时,mySwitch Retain 为 2,每次我点击开关时,保留计数都会增加,直到达到 4,然后它似乎就停留在那里。
显然我错过了一些东西。如果有人能指出我正确的方向,将不胜感激。