source

UITableView를 편집하는 동안 "-" (삭제) 버튼을 숨길 수 있는 방법이 있습니까?

factcode 2023. 9. 6. 22:24
반응형

UITableView를 편집하는 동안 "-" (삭제) 버튼을 숨길 수 있는 방법이 있습니까?

제 아이폰 앱에서는 편집 모드의 UITableView가 있는데, 사용자는 삭제 권한이 주어지지 않은 행만 재정렬할 수 있습니다.

그렇다면 테이블뷰에서 "-" 빨간색 버튼을 숨길 수 있는 방법이 있을까요?알려주세요.

감사해요.

셀의 압흔(0좌측 정렬)이 없는 완벽한 솔루션입니다!

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    return YES;
}

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
    return UITableViewCellEditingStyleNone; 
}

- (BOOL)tableView:(UITableView *)tableview shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath {
    return NO;
}


- (BOOL)tableView:(UITableView *)tableview canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    return YES;
}

스위프트 5는 필요한 기능만 있으면 수용된 답변과 맞먹습니다.

extension YourViewController: UITableViewDelegate {
    func tableView(_ tableView: UITableView, shouldIndentWhileEditingRowAt indexPath: IndexPath) -> Bool {
        return false
    }

    func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCell.EditingStyle {
        return .none
    }
}

그러면 들여쓰기가 중지됩니다.

- (BOOL)tableView:(UITableView *)tableview shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath {
    return NO;
}

'(-)' 삭제 버튼이 아닌 편집 모드에서 사용자 지정 확인란이 뜨기를 바라는 유사한 문제에 직면했습니다.

스테판의 대답이 저를 올바른 방향으로 이끌었습니다.

Toggle 버튼을 만들어 편집AccessoryView로 Cell에 추가하고 방법에 배선하였습니다.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    ....
    // Configure the cell...

    UIButton *checkBoxButton = [[UIButton alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 40.0f, 32.0f)];
    [checkBoxButton setTitle:@"O" forState:UIControlStateNormal];
    [checkBoxButton setTitle:@"√" forState:UIControlStateSelected];
    [checkBoxButton addTarget:self action:@selector(checkBoxButtonPressed:) forControlEvents:UIControlEventTouchUpInside];

    cell.editingAccessoryType = UITableViewCellAccessoryCheckmark;
    cell.editingAccessoryView = checkBoxButton;

    return cell;
}

- (void)checkBoxButtonPressed:(UIButton *)sender {
    sender.selected = !sender.selected;
}

이러한 대리인 방법을 구현했습니다.

- (BOOL)tableView:(UITableView *)tableview shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath {
    return NO;
}

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
    return UITableViewCellEditingStyleNone;
}

편집 중에 (-) 점만 숨기려고 할 때, 사용자의 삭제 기능을 그대로 유지하고 싶을 때는 이렇게 실행합니다.UITableViewDelegate프로토콜 적합 클래스

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (self.editing) return UITableViewCellEditingStyleNone;
    return UITableViewCellEditingStyleDelete;
}

언급URL : https://stackoverflow.com/questions/3020922/is-there-any-way-to-hide-delete-button-while-editing-uitableview

반응형