2011-11-06 2 views
4

리셋 버튼을 코딩하려고하는데, 그 버튼을 클릭하면 모든 tableview 셀의 액세서리 유형이 none으로 설정됩니다.버튼 클릭으로 tableview 셀 accessorytype을 none으로 재설정하는 방법은 무엇입니까?

나는 그것을하는 방법에 대한 명확한 개념을 가지고 있지만, iPhone 개발에 익숙하지 않아 전화 할 방법에 대한 도움이 필요합니다.

걸릴 단계 : for 루프를 사용하여 모든 행을 반복합니다. - 셀 수가 성공적으로 계산됩니다. 내 문제는, 나는 그 행/셀 각각에 대해 검사 할 방법이 없다는 것입니다. 액세서리 유형이 CheckMark이고 none으로 설정 한 경우입니다.

또한, 나는 AccessoryNone 내 모든 셀을 설정할 수 있습니다,하지만 난 이미 내부에 약간의 계산을하고있는 중이 야 :

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 

그래서 내가 이것을 달성하는 방법을 모르겠습니다.

답변

10

accessoryType이 무엇인지 먼저 확인할 필요가 없습니다. 모두 UITableViewCellAccessoryNone을 할당하면됩니다. 이것은 당신이 무엇을하려고 작동한다 :

// replace clickedResetButton with your action handler method for that button 
- (IBAction)clickedResetButton:(id)sender { 
    for (int section = 0, sectionCount = self.tableView.numberOfSections; section < sectionCount; ++section) { 
     for (int row = 0, rowCount = [self.tableView numberOfRowsInSection:section]; row < rowCount; ++row) { 
      UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:row inSection:section]]; 
      cell.accessoryType = UITableViewCellAccessoryNone; 
      cell.accessoryView = nill; 
     } 
    } 
} 
+0

감사합니다! 그 견해가 끝내야한다는 것을 깨닫지 못했다. – pulkitsinghal

0

스위프트 3.1

func resetAccessoryType(){ 
    for section in 0..<self.tableView.numberOfSections{ 
     for row in 0..<self.tableView.numberOfRows(inSection: section){ 
      let cell = self.tableView.cellForRow(at: IndexPath(row: row, section: section)) 
      cell?.accessoryType = .none 
     } 
    } 
} 
관련 문제