2012-02-24 33 views
1

我到目前爲止使用TableView時遇到的所有示例都使用UITableViewController。但我想在UIViewController中使用它。我在視圖頂部放置了一個Label,並在其下面放置了一個TableView。MonoTouch:當在TableView中選擇一行時,DataSource.RowSelected()不會觸發

我可以根據需要在行中顯示數據。

 public override void ViewDidLoad() 
    { 
     base.ViewDidLoad(); 

     // Perform any additional setup after loading the view, typically from a nib. 
     selectedDate = Convert.ToDateTime (Application.selectedDateTime.ToShortDateString()); 
     lblCurrentDateValue.Text = "Date currently set to: " + selectedDate.ToShortDateString(); 

     // Create option list for date selection 
     DateTime now = DateTime.Today; 
     arrayOptionCells = new DateSelectionOptionCell[] 
     { 
      new DateSelectionOptionCell ("Yesterday", FormattedDateString (2, now.AddDays (-1)), null), 
      new DateSelectionOptionCell ("Today", FormattedDateString (2, now), null), 
      new DateSelectionOptionCell ("Tomorrow", FormattedDateString (2, now.AddDays (1)), null), 
      new DateSelectionOptionCell ("Day After", FormattedDateString (2, now.AddDays (2)), null), 
      new DateSelectionOptionCell ("n - Days after    n =>", FormattedDateString (2, now.AddDays (7)), TFDaysAfter()), 
      new DateSelectionOptionCell ("Select Date Picker", FormattedDateString (2, now), null) 
     }; 

     tblvDateSelection.Source = new DataSource(this); 
     tblvDateSelection.Delegate = new DateSelectionTableDelegate(); 
     tblvDateSelection.ReloadData(); 
    } 

在上面的代碼中,tblvDateSelection是TableView。但是DataSource.RowSelected(...)在觸摸一行/一節時不會觸發。我將類DataSource代碼與那些工作示例進行了比較,但使用UITableViewController而不是UIViewController。

RowSelected沒有被解僱的原因是什麼?

ThanQ ...

回答

2

的問題似乎是,你同時設置UITableViewSource的UITableViewDelegate,在UITableViewSource實際上是爲你設置兩個UITableViewDataSource的UITableViewDelegate,如果你做一個輔助方法沒有設置UITableViewDelegate,那麼這應該爲你工作。

+0

謝謝@chrisntr。有用。 – ESM 2012-02-28 23:04:37

0

我有一個類似的問題...礦似乎是調試器,沒有違反在RowSelect我的破發點。所以它好像沒有被調用!

他們已經解決了在最新的調試器中突破「超級虛擬方法」的問題。

+0

那麼,你做了什麼來解決它? – ESM 2012-02-25 00:36:10

+0

它仍然在發生......你的問題是否一樣?你可以使用Console.WriteLine來檢查。 – AnthonyLambert 2012-02-27 14:19:22

+0

是的,我的問題已由@chrisntr給出解決。如果將DataSource設置爲UITableViewDataSource,則在TableView.Delegate類中使用RowSelected()。如果DataSource來自UITableViewSource,則不要在DataSource中設置Delegate並使用RowSelected()。 – ESM 2012-02-28 23:03:48

相關問題