【发布时间】:2015-05-28 06:09:00
【问题描述】:
当开关打开时,我的 tableview 中有开关,我需要更改 tableview 单元格内的视图,因为我已经写了
-(void)didchangeswitchpostion:(UISwitch *)sender{
[tasklogtableview reloadRowsAtIndexPaths:@[reloadindexpath] withRowAnimation:UITableViewRowAnimationNone];
}
在我已经完成的索引路径的行的单元格中
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;{
static NSString *cellidentifier=@"cellidentifier";
cell=(TaskLogTableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellidentifier];
if (cell==nil) {
NSArray *nib=[[NSBundle mainBundle]loadNibNamed:@"TaskLogTableViewCell" owner:self options:nil];
cell=[nib objectAtIndex:0];
}
if ([cell.autoswitch isOn]) {
cell.lblfrom.hidden=YES;
cell.lblhours.hidden=YES;
cell.lblfromtime.hidden=YES;
}
return cell;
}
但我无法打开开关,重新加载单元格是否有任何问题。
【问题讨论】:
-
确保开关控制superview不是UILabel那样的view,因为不能得到点击事件,并且确保没有任何清晰的背景色view覆盖它,你可以看到开关,但是无法获取点击事件。
-
你需要一个
if ([cell.autoswitch isOn])的 else 语句,另一个是你如何将 BOOL 分配给cell.autoswitch?您需要有一个“选定的 indexVariable”来检查这是否是您打开开关的索引..
标签: ios objective-c uitableview uiswitch