2013-08-13 33 views
6

Tôi muốn sử dụng tùy chọn "vuốt để xóa" trong dự án của tôi.Vuốt để xóa tùy chọn trong các sự cố UITableView

-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

    if (editingStyle == UITableViewCellEditingStyleDelete) 
    { 
     NSDictionary *userData = [_contactsArray objectAtIndex:indexPath.row]; 
     NSLog(@"delete row %@",userData); 
    } 
} 

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

    return YES; 
} 

Tôi đang sử dụng mã này nhưng nó cung cấp cho sản lượng sau mà tôi không muốn. enter image description here

Tôi không muốn dấu trừ bên trái đó trên ô. Tôi chỉ muốn vuốt và hiển thị nút xóa. Cùng mã tôi đã sử dụng trong dự án trước đó và nó hoạt động tốt (chỉ vuốt để hiển thị nút xóa, không có dấu trừ ở bên trái)

Vui lòng giúp tôi giải quyết vấn đề này.

+0

http://developer.apple.com/library/ios/documentation/uikit/reference/UITableViewCell_Class/Reference/Reference.html#//apple_ref/occ/instp/UITableViewCell/shouldIndentWhileEditing – Kevin

+0

http://stackoverflow.com/questions/3020922/is-there-any-way-to-hide-delete-button-while-edit-uitableview – Rushabh

+0

Bạn đang ghi đè các phương thức UITableViewDelegate chính xác. Nhưng bạn có thiết lập thuộc tính 'chỉnh sửa' của UITableView thành 'YES' ở bất kỳ đâu trong mã của bạn không? Nếu vậy, điều đó sẽ làm cho các dấu trừ màu đỏ bị hiển thị. – hgwhittle

Trả lời

9

Bạn đang ghi đè các phương thức ủy quyền chính xác cho chức năng 'vuốt để xóa'. Về những dấu hiệu trừ:

Ẩn trừ dấu hiệu như thế này:

self.yourTableView.editing = NO; 
//or simply remove this line of code altogether because this property is NO by default 

Hiện dấu trừ như thế này:

self.yourTableView.editing = YES; 
1

Hãy thử điều này:

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { 
     // Return YES if you want the specified item to be editable. 
     return YES; 
    } 

    // Override to support editing the table view. 
    - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { 
     if (editingStyle == UITableViewCellEditingStyleDelete) { 
      //add code here for when you hit delete 
     }  
    } 
0

Âm thanh như bạn đang chuyển sang các tableView.editing cờ trên nên các hàng xuất hiện với dấu trừ. hãy thử tìm kiếm self.tableView.editing = YES; và biến nó thành NO hoặc chỉ cần nhận xét dòng đó.

3

Đầu tiên tạo ra xem bảng của bạn và thiết lập đại biểu và nguồn dữ liệu phương pháp đó.

self.contacts=[[UITable alloc]init]; 
    self.contacts.dataSource=self; 
    self.contacts.delegate=self; 
    self.contacts.userInteractionEnabled=YES; 
    //self.contacts.editing = YES; 
    [self.view addSubview:self.contacts]; 

Và sau đó ghi đè phương thức nguồn đại biểu và nguồn dữ liệu để xóa ghi đè các phương pháp sau.

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { 
     // Return YES if you want the specified item to be editable. 
     return YES; 
    } 

    // Override to support editing the table view. 
    - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { 
     if (editingStyle == UITableViewCellEditingStyleDelete) { 
      //add code here for when you hit delete 
     }  
    } 

Dấu trừ ở bên trái sử dụng self.contacts.editing = YES; Trong trường hợp của tôi, tôi không muốn ký hiệu trừ này vì vậy chỉ đơn giản là không sử dụng thuộc tính đó hoặc đặt self.contacts.editing = NO;

Cảm ơn bạn hw731 để nhắc tôi về tài sản này, tôi đã lãng phí nửa ngày của mình về điều này.

Các vấn đề liên quan