2017-06-05 12 views
0

テーブルセルをクリックすると、セグを使用して新しいページに移動したいと思います。しかし、私がセルをクリックするたびに何も起こりません。iOSテーブルセルの新しいビューへの移動Segueを使用してクリック

PrepareForSegueメソッドにブレークポイントを配置すると、DayTableViewのセルをクリックすると決してヒットしません。

Main.storyboard enter image description here

DayTableViewController

namespace HHGoals2 
{ 
    public partial class DayTableViewController : UITableViewController 
    { 
     HHGoals2DataService dataService = new HHGoals2DataService(); 

     public DayTableViewController(IntPtr handle) : base (handle) 
     { 
     } 

     public override void ViewDidLoad() 
     { 
      var allDays = dataService.GetAllDays(); 
      var dataSource = new GoalsDataSource(allDays, this); 

      TableView.Source = dataSource; 

      this.NavigationItem.Title = "Completed Goals"; 
     } 

     public override void PrepareForSegue (UIStoryboardSegue segue, NSObject sender) 
     { 
      base.PrepareForSegue(segue, sender); 

      if(segue.Identifier == "GoalDetailSegue") 
      { 
       var goalDetailViewController = segue.DestinationViewController 
                as GoalDetailViewController; 
       if(goalDetailViewController != null) 
       { 
        var source = TableView.Source as GoalsDataSource; 
        var rowPath = TableView.IndexPathForSelectedRow; 
        var item = source.GetItem(rowPath.Row); 
        goalDetailViewController.SelectedDay = item; 
       } 

      } 
     } 
    } 
} 

GoalsDataSource

using System; 
using Foundation; 
using UIKit; 
using System.Collections.Generic; 
using HHGoals2.Core.Model; 
using HHGoals2.Cells; 

namespace HHGoals2.DataSources 
{ 
    public class GoalsDataSource: UITableViewSource 
    { 
     private List<Day> allDays; 
     NSString cellIdentifier = new NSString("DayCell"); 
     DayTableViewController callingController; 

     public GoalsDataSource(List<Day> allDays, DayTableViewController callingController) 
     { 
      this.allDays = allDays; 
      this.callingController = callingController; 
     } 

     public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath) 
     { 
      DayListCell cell = tableView.DequeueReusableCell(cellIdentifier) as DayListCell; 

      if (cell == null) 
      { 
       cell = new DayListCell(cellIdentifier); 
      } 


      cell.UpdateCell(allDays[indexPath.Row].Number.ToString(), 
          allDays[indexPath.Row].SuccessRate.ToString(), 
          allDays[indexPath.Row].FailRate.ToString()); 

      return cell; 
     } 

     public override nint RowsInSection(UITableView tableview, nint section) 
     { 
      return allDays.Count; 
     } 

     public Day GetItem(int id) 
     { 
      return allDays[id]; 
     } 

    } 
} 

私はDayCellのTouchUpInsideイベントを追加する必要がありますか?どのようにこれを動作させるための任意の提案は素晴らしいだろう。

+1

[彼の答え](https://stackoverflow.com/questions/22759167/how-to-make-a-push-segue-when-a-uitableviewcell-is-selected)をご確認ください。 –

+0

提案のためのThx。 2番目の答えによると、鉱山はうまくいくはずです。明らかに、そんなに損失を与えることはありません。 。 。 。 – RyeGuy

+1

これはあなたの完全な 'DayTableViewController'ですか?データを設定したり、作成したビューの 'GetView'メソッドを返すのはどこですか? – apineda

答えて

1

uituitviewcontrollerのテーブルビューにデリゲートとデータソースを接続していないと思います。それでそれを接続し、それは正常に動作します。

+0

私はあなたが正しいかもしれないと信じています。しかし、私はすでにそれをした印象を受けています。コード例を提供できますか?それが動作する場合は、私はあなたに緑のチェックを与えることを確認します – RyeGuy

+0

self.tableView.delegate =自己 self.tableView.dataSource = self – sumeet

関連する問題