테이블보기에서 한 번에 두 행만 선택할 수 있도록하려고 시도하지만 좋은 결과를 얻을 수없는 것 같습니다!iOS의 tableview에서 두 행만 선택하는 방법은 무엇입니까?
하나의 행을 선택하면 핵심 데이터에 개체가 전송 된 다음 다른 데이터를 핵심 데이터로 보내는 두 번째 행을 선택할 때 아이디어가 생성됩니다. 그러나 두 행 이상을 선택하면 두 행만 선택할 수 있다는 경고보기가 표시됩니다.
NSArray *indexPathArray = [[NSArray alloc]init];
indexPathArray = [self.mainTableView indexPathsForSelectedRows];
if (indexPathArray.count == 1) {
NSLog(@"%@",@"we have 1 cell selected");
}
if (indexPathArray.count == 2) {
NSLog(@"%@",@"We have 2 cells selected!");
}
if (indexPathArray.count > 2) {
NSLog(@"%@",@"ERROR ERROR!!!");
}
와 나는 많은 다른 구글과 스택 오버 플로우 제안을 시도했지만 종료하지 않았다 :
나는이 시도했다!
어떻게하면됩니까? 당신의 didSelectRowAtIndexPath:
방법에서
[tableView deselectRowAtIndexPath:indexPath animated:YES];
:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath(NSIndexPath*)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
[self setSelection:indexPath];
_profile = [self.fetchedResultsController objectAtIndexPath:indexPath];
NSInteger rowNumber = 0;
for (NSInteger i = 0; i < indexPath.section; i++) {
rowNumber += [self tableView:tableView numberOfRowsInSection:i];
}
rowNumber += indexPath.row;
NSLog(@"%ld",(long)rowNumber);
NSArray *indexPathArray = [[NSArray alloc]init];
indexPathArray = [self.mainTableView indexPathsForSelectedRows];
if (indexPathArray.count == 1) {
NSLog(@"%@",@"we have 1 cell selected");
}
if (indexPathArray.count == 2) {
NSLog(@"%@",@"We have 2 cells selected!");
}
if (indexPathArray.count > 2) {
NSLog(@"%@",@"ERROR ERROR!!!");
}
[tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade]; }
현재 솔루션이 어떤면에서 예상대로 작동하지 않습니까? –
'self.mainTableView.allowsMultipleSelection = true'를 설정 했습니까? – pbasdf
하나, 둘 또는 그 이상의 행을 선택할 때, 거기에있는 NSLog가 보이지 않습니다 ... – eeschimosu