내가 가지고 UItableView
내 질문에 내 코드에서 UITableViewCell
동적으로 UITableView의 UISwitch를 어떻게 변경할 수 있습니까?
의 난 OFF
다른 스위치는 이미 뷰를 만들어 내가 한 방법 난 후 하나 개의 스위치를 클릭 할 때입니다 부탁해 모든 UITableViewCell
는 UISwitch
가 포함되는 경우 ON/OFF
스위치를 사용할 수 있습니다. 그러나 OFF
다른 모든 스위치는 내 선택한 스위치를 제외하고 싶습니다.
예제 나 소스 코드 예를 통해 도움을주십시오. 베스트 감사와
편집
내 코드 :
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
switchview = [[UISwitch alloc] initWithFrame:CGRectZero];
cell.accessoryView = switchview;
switchCondition = NO;
[switchview setOn:NO animated:YES];
[switchview addTarget:self action:@selector(updateSwitchAtIndexPath:) forControlEvents:UIControlEventValueChanged];
[switchview release];
}
if(switchCondition == YES){
[switchview setOn:YES animated:YES];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.contentView.backgroundColor = [UIColor clearColor];
cell.textLabel.text = [NSString stringWithFormat:@"%@",[cellValueArray objectAtIndex:indexPath.row]];
return cell;
}
- (void)updateSwitchAtIndexPath:(UISwitch*)sender {
if(sender.on){
switchCondition = YES;
[table reloadData];
}
}
빠른 답변 감사합니다. 내가 어떻게 할 수 있는지 이해할 수 없어서 예제를주세요. – Emon
'cellForRowAtIndexPath :'에 대한 코드를 보여주세요 (질문 업데이트). 각 행에 대한 스위치 설정 방법을 보여줍니다. 또한 스위치 값이 변경 될 때 이벤트 처리에 대한 코드도 표시하십시오. – rmaddy
질문이 있습니다. 지금해야 할 일을 확인하십시오. – Emon