저는 2 개의 tableview 컨트롤러가 있습니다. 첫 번째 tableview에는 첫 번째 tableview의 cellforRowAtIndexPath에 버튼이 있습니다. 처음에는 버튼 이미지를 '켜짐'이미지로 설정하여 내 알람이 켜져 있음을 나타냅니다. 그런 다음 편집 버튼을 클릭하면 내 버튼 이미지가 'OFF'로 바뀌는 editmode로 변경됩니다. tableview 편집 모드로 입력 할 때 호출해야합니다. 이것은 내가 작성한 코드입니다.토글 버튼 값을 전달하여 아이폰의 다른 클래스에서 버튼 상태를 전환합니다.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *CellIdentifier = [NSString stringWithFormat:@"Cell%d%d", indexPath.section, indexPath.row];
appDelegate = (StopSnoozeAppDelegate*)[[UIApplication sharedApplication]delegate];
TAlarmCell *cell =(TAlarmCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[TAlarmCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
mimageButton = [UIButton buttonWithType:UIButtonTypeCustom];
mimageButton.frame=CGRectMake(10, 20, 20, 20);
mimageButton.tag = 1;
[mimageButton setImage:[UIImage imageNamed:@"alarm_ON.png"] forState:UIControlStateNormal];
[mimageButton setImage:[UIImage imageNamed:@"alarm_OF.png"] forState:UIControlStateSelected];
[cell.contentView addSubview:mimageButton];
}
cell.editingAccessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
// 이것은 나의 편집 코드입니다.
-(void)setEditing:(BOOL)editing animated:(BOOL)animated
{
[super setEditing:editing animated:animated];
[mTableView setEditing:editing animated:YES];
if (editing)
{
[mimageButton addTarget:self action:@selector(changeMapType:) forControlEvents: UIControlEventTouchUpInside];
self.navigationItem.rightBarButtonItem = nil;
}
else {
self.navigationItem.rightBarButtonItem = addButton;
[self.mTableView reloadData];
}
}
//이 내 버튼 액션
-(void)changeMapType:(UIButton *)sender
{
NSIndexPath *indexPath =[self.tableView indexPathForCell:(UITableViewCell *)[[sender superview] superview]];
NSUInteger row = indexPath.row;
NSLog(@"row...%d",row);
appDelegate.changeimagetype = !appDelegate.changeimagetype;
sender.selected = appDelegate.changeimagetype;
[self.tableView reloadData];
}
입니다하지만 편집 버튼을 클릭하고있는 tableview 편집 모드에 들어갈 때 여기에서 문제는 changeMapType은 다음과 같습니다 조치가 호출 받고되지 않고 내 이미지가 않습니다 변경되지 않습니다. u는이 플래그
if (editing)
및 사용자의 행동을 설정 r에 어디
아래의 방법을 사용할 수 있습니다 버튼의 이미지는 해당 특정 셀만 변경해야합니다. 내 문제는 버튼을 클릭 할 때 이미지가 모든 indexpath에 대해 변경된 후 다른 버튼에있는 스위치 버튼에 버튼 상태를 전달하려는 것입니다. – Rani