Trong ứng dụng của tôi, tôi đang sử dụng UITableview. Trong đó phương pháp đại biểu didselectrow nếu tôi thực hiện bất kỳ hoạt động không thể xảy ra chỉ.UITableview - tableView: didDeselectRowAtIndexPath: phương thức không hoạt động đúng?
Ví dụ tôi có 3 hàng trong tableview
nếu tôi chọn 1 hàng (indexPath.row == 0) không có gì sẽ xảy ra
nếu một lần nữa chọn 2 hàng (indexPath.row == 1) bây giờ nó là Logging in console indexPath.row == 0 là giá trị trước đó.
nếu chọn lại 1 hàng thì ghi nhật ký chỉ mục giá trị trước đó của nóPath.row = 1.
Lý do điều này xảy ra.
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
CustomerInfoViewController *customer = [[EquipmentViewController alloc]initWithNibName:@"CustomerInfoViewController" bundle:nil];
EquipmentViewController *equpment = [[EquipmentViewController alloc]initWithNibName:@"EquipmentViewController" bundle:nil];
ContactsViewController *contacts = [[ContactsViewController alloc]initWithNibName:@"ContactsViewController" bundle:nil];
if(indexPath.row == 0)
{
NSLog(@"one %d",indexPath.row);
[detailsView addSubview:customer.view];
}
if(indexPath.row == 1)
{
NSLog(@"two %d",indexPath.row);
[detailsView addSubview:equpment.view];
}
if(indexPath.row == 2)
{
NSLog(@"three%d",indexPath.row);
[detailsView addSubview:contacts.view];
}
}
Vui lòng bất cứ ai giúp tôi.
Xin cảm ơn trước.
Hiển thị một số mã thực tế có thể? – Vladimir
Dường như chính xác về mặt logic. Có thể kéo các khởi tạo vào các câu lệnh if. Nó có thể có gì để làm với các phần? Có thể làm 'NSLog (@"% d% d ", indexPath.row, indexPath.section);' để xem hàm có được gọi hay mã của bạn không đúng. Bạn phải xóa một số tùy chọn để hiểu rõ hơn về vấn đề. – DAS