Reputation: 4483
Upon clicking a table cell I would like to navigate to a new page using a segue. However whenever I click the cell nothing happens.
When I place a breakpoint on the PrepareForSegue method it is never hit when I click a cell on the DayTableView.
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];
}
}
}
Do I need to add a TouchUpInside event of the DayCell? Any suggestions on how to get this to work would be great.
Upvotes: 0
Views: 518
Reputation: 157
I think you just missed out to connect the delegate and datasource to tableview in uitableviewcontroller. So connect it and it will work fine.
Upvotes: 1