Я пытаюсь распечатать значение того места, где пользователь щелкнул, в методе, который вызывается, когда пользователь обновляет значение UISwitch
в некоторых ячейках. Есть четыре ячейки, в которых UISwitch
установлен как аксессуар ячейки. У меня уже есть инфраструктура для проверки значений вызова [self.basicObjects objectAtIndex:indexPath.row]
, но проблема в том, что независимо от того, какую ячейку я нажимаю, вызывается значение 0
NSMutableArray
, содержащее заголовки четырех ячеек.
- (void)switchChanged:(id)sender cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"self.basicObjects value: %@", [self.basicObjects objectAtIndex:indexPath.row]);
}
В качестве примечания, когда я просматривал похожие вопросы, мне также показалось важным отметить, что self.settingsTable
представляет собой сгруппированное UITableView
с этими четырьмя ячейками, находящимися в разделе 1 (0, 1, 2). Два других раздела не содержат UISwitch
в качестве вспомогательного типа, это только этот раздел, и только этот раздел ссылается на метод switchChanged:cellForRowAtIndexPath:
.
Изменить — 19:31
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"TableCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:simpleTableIdentifier];
}
cell.textLabel.font = [UIFont fontWithName:@"HelveticaNeue-Light" size:17.5];
if (indexPath.section == 0)
{
// change the text to standard case
// change text color
}
else if (indexPath.section == 1)
{
cell.textLabel.text = [self.basicObjects objectAtIndex:indexPath.row];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
self.switchProperty = [[UISwitch alloc] initWithFrame:CGRectZero];
cell.accessoryView = self.switchProperty;
if ([[self.basicStatus objectAtIndex:indexPath.row] isEqual:@"YES"])
{
[self.switchProperty setOn:YES animated:YES];
[self.switchProperty addTarget:self action:@selector(switchChanged:cellForRowAtIndexPath:) forControlEvents:UIControlEventValueChanged];
}
else if ([[self.basicStatus objectAtIndex:indexPath.row] isEqual:@"NO"])
{
[self.switchProperty setOn:NO animated:YES];
[self.switchProperty addTarget:self action:@selector(switchChanged:cellForRowAtIndexPath:) forControlEvents:UIControlEventValueChanged];
}
}
else if (indexPath.section == 2)
{
cell.textLabel.text = [self.objects objectAtIndex:indexPath.row];
cell.detailTextLabel.text = [self.objectsType objectAtIndex:indexPath.row];
cell.detailTextLabel.font = [UIFont fontWithName:@"HelveticaNeue-Light" size:17.5];
if ([[self.objectsStatus objectAtIndex:indexPath.row] isEqual:@"Setup"])
cell.detailTextLabel.textColor = [UIColor colorWithRed:0.298 green:0.851 blue:0.392 alpha:1]; // #4CD964 (green)
else if ([[self.objectsStatus objectAtIndex:indexPath.row] isEqual:@"Not Setup"])
cell.detailTextLabel.textColor = [UIColor colorWithRed:0.898 green:0.267 blue:0.267 alpha:1]; // #E54444 (red)
}
return cell;
}
tableView:cellForRowAtIndexPath:
метод. - person Dima   schedule 09.07.2014