2012-10-01 41 views
1

我用IB在Storyboard中創建了UITableViewController。我將UITableview'sdelegate設置爲其控制器。 UITableView有靜態單元格。只有2個部分。第一部分有3個不可選擇的行。最後一節有1行可供選擇。我只在IB中設置了這一點。UITableViewDelegate方法沒有被調用

然後我在UITableViewController中實現了這個方法。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    NSLog(@"SELECTED"); 

    if (indexPath.section == 1 && indexPath.row == 0) { 
     //login and report the result 
     [self login]; 
    } 
} 

當我在第二部分中選擇唯一一行時,上述方法沒有被調用。出了什麼問題。我也仔細檢查了UITableView的網點檢查員的代表設置。一切安好!

+0

你確定你實現-tableView:didSelectRowAtIndexPath方法:不-tableView:didDeslectRowAtIndexPath:? – Moxy

+0

@Moxy是的。我做到了。 – Anand

+0

您是否在.h文件中添加了? – AndyDev

回答

0

您是否在控制檯中看到NSLog語句?怎麼樣在viewDidAppear,NSLog(@"Delegate: %@",tableView.delegate)

見,如果你在控制檯中得到NULL。

您知道dataSource已正確連接,否則您不會看到任何單元格。這是你的代表連接=)

1

只是這樣做: 控制拖動你的tableView從Storyboard到viewcontroller .h文件,創建@property爲前。的tableView。再次添加到.h文件。然後在 viewDidLoad中.m文件這樣寫:

-(void)viewDidLoad{ 
     //your other code 
     self.tableView.delegate = self; 
     self.tableView.dataSource = self; 
     //other code ... 
    } 

我更喜歡使用tblView財產的名字,因爲你會看到警告的tableView隱藏實例。希望這個幫助。

相關問題