2013-07-15 30 views
5

Chào khi ở chế độ chỉnh sửa chế độ xem bảng, chức năng didselectrowatindexpath không được gọi. Đây là mã của tôi. Có sai sót với mã của tôi không?ios didselectrowatindexpath không được gọi khi ở chế độ chỉnh sửa

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    if (self.tableView.editing == YES) { 
     NSLog(@"now in editing mode"); 
    } 
    else { 
     NSLog(@"now in normal mode"); 
    } 
} 

- (void)setEditing:(BOOL)editing animated:(BOOL)animated { 
    [super setEditing:editing animated:animated]; 
    // must be called first according to Apple docs 
    [self.tableView setEditing:editing animated:animated]; 
} 

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

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

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

help.Thanks Hãy

+0

bạn có thể thêm đại biểu của tableview – Jitendra

+0

kiểm tra cho dù bạn thiết lập đại biểu của UITableView tự (hoặc lớp trong đó có didselectrowatindexpath thực hiện chức năng) .. – Suryakant

Trả lời

16

Bạn phải thiết lập thuộc tính này allowsSelectionDuringEditing của UITableView-TRUE để có thể chọn hàng trong khi chế độ Editing. Vì vậy, nó phải được

self.tableView.allowsSelectionDuringEditing=YES; 
+0

Với iOS 9, didSelectRowAtIndexPath không bao giờ được gọi là trong khi ở chế độ chỉnh sửa ngay cả với allowsSelectionDuringEditing = CÓ. Thay vào đó, bạn có thể thực hiện willSelectRowAtIndexPath-- nó sẽ được gọi nếu bạn cũng đặt allowSelectionDuringEditing = YES. – lifjoy

1

Tôi không tin nó được kích hoạt theo mặc định, nhưng bạn phải xác định những lựa chọn nên được cho phép trong chỉnh sửa, giống như bạn để lựa chọn không chỉnh sửa. Sử dụng một trong hai dòng sau tùy thuộc vào những gì bạn cần.

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    [self.tableView setAllowsMultipleSelectionDuringEditing:YES]; 
    [self.tableView setAllowsSelectionDuringEditing:YES]; 
} 
Các vấn đề liên quan