2010-06-11 33 views

Trả lời

241

Đây là giải pháp hoàn chỉnh của tôi, không có thụt đầu dòng (khớp 0 độ) của ô!

- (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; 
} 
+1

trình một cách hoàn hảo, cảm ơn! –

+1

hoàn hảo .... cảm ơn bạn. – CKT

+1

tốt nhất + cho công việc tốt đẹp – Warewolf

3

này dừng thụt đầu dòng:

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

tôi phải đối mặt với một vấn đề tương tự mà tôi muốn hộp kiểm tùy chỉnh để xuất hiện trong chế độ Edit nhưng không phải là - nút xóa '()'.

Stefan's answer hướng tôi đi đúng hướng.

Tôi đã tạo nút chuyển đổi và thêm nút này làm chỉnh sửaAccessoryView vào Ô và kết nối nó với phương thức.

- (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; 
} 

thực hiện những phương pháp đại biểu

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

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

Swift 3 tương đương với câu trả lời chấp nhận chỉ với funcs cần thiết:

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

func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCellEditingStyle { 
    return .none 
} 
Các vấn đề liên quan