사용자가 일부 셀의 UISwitch
값을 업데이트 할 때 호출되는 메서드에서 사용자가 클릭 한 값을 인쇄하려고합니다. 셀의 부속품으로 UISwitch
이 설정된 네 개의 셀이 있습니다. 이미 [self.basicObjects objectAtIndex:indexPath.row]
을 호출하는 값과 대조 할 수있는 인프라가 있지만 문제는 어떤 셀을 눌러도 0
값이 4 개의 셀 제목을 포함하는 NSMutableArray
입니다. 보조 노트로 NSIndexPath는 첫 번째 셀 값만 가져옵니다.
- (void)switchChanged:(id)sender cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"self.basicObjects value: %@", [self.basicObjects objectAtIndex:indexPath.row]);
}
, 나는 비슷한 질문을보고 있었다, 그것은 또한
self.settingsTable
이 4 개의 셀 섹션 1에있는로 그룹화
UITableView
것을주의하는 것이 중요 듯 (0, 1, 2). 다른 두 섹션에는 액세서리 유형으로
UISwitch
이 포함되어 있지 않으며이 섹션 만이
switchChanged:cellForRowAtIndexPath:
메소드를 참조합니다.
편집 - 오후 7시 31분 당신은 당신의 액션 메소드 방식으로 indexPath를 통과 할 수
- (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 :'메소드를 보여주세요. – Dima