2013-08-05 31 views
0

我有一个导航控制器上显示的表列表O产品,那么我需要触摸的项目的显示这个项目的细节。的MonoTouch获得行项目选择

这是我的如何填写表格代码:因为我用故事板,以显示详细信息视图控制器我有这样的代码在我的表源

public void SearchHotel(){ 

    Hotel hotel = new Hotel(); 
    var distribution = new HotelDistribution[]{new HotelDistribution(){ Adults = 1, Children = 0, ChildrenAges = new int[0]} }; 
    var items = hotel.SearchHotels(Convert.ToDateTime("2013-08-08"),Convert.ToDateTime("2013-09-09 "),"(MIA)", distribution,"","","",0); 


    data = new List<DtoHotelinformation>(); 

    foreach (var item in items) 
    { 
     DtoHotelinformation DtoHotelinformation = new DtoHotelinformation(); 
     DtoHotelinformation.code = item.Code.ToString(); 
     DtoHotelinformation.price = item.Price.ToString(); 
     DtoHotelinformation.title = item.Name.ToString().ToTitleCase(); 
     DtoHotelinformation.subtitle = item.Address.ToString(); 
     DtoHotelinformation.rating = item.Rating.ToString(); 
     DtoHotelinformation.imageUlr = item.ImageUrl; 

     data.Add(DtoHotelinformation); 
    } 

    hud.Hide(true); 
    hud.RemoveFromSuperview(); 
    HotelSearchTable.Source = new HotelTableSource(data.ToArray()); 
    HotelSearchTable.ReloadData(); 

} 

public override void RowSelected (UITableView tableView, NSIndexPath indexPath) 
{ 

    if (RowTouched != null) { 
     RowTouched (this, EventArgs.Empty); 
    } 
    tableView.DeselectRow (indexPath, true); // normal iOS behaviour is to remove the blue highlight 
} 

返回到我的视图控制器我打电话RowTouched以显示详细信息控制器,如下所示:

public override void ViewDidAppear (bool animated) { 
    base.ViewDidAppear (animated); 
    SearchHotel(); 

    var source = new HotelTableSource(data.ToArray()); 
    var detail = Storyboard.InstantiateViewController("HotelDetailScreen") as iPhoneHotelDetailViewController; 
    source.RowTouched += (sender, e) => { 
     this.NavigationController.PushViewController(detail, true); 

    }; 
    HotelSearchTable.Source = source; 

} 

但我需要通过桌面上的项目信息来显示细节。我真的不知道我必须做什么?

注:我不能使用PrepareForSegue因为我没有控制器之间SEGUE。

在此先感谢

回答

0

如果你愿意,你可以在你的行选择时,你的表数据源的内得到您的UINavigationController 的保持。

从那里你可以推你的新的ViewController。

[indexPath.Row]在“Row_Selected”应该告诉你的是,用户选择哪个元素的数组或列表中。

UINavigationController navcontroller =(UINavigationController)UIApplication.SharedApplication.Windows[0].RootViewController; 
0

传递数据到事件处理程序是Exarly EventArgs参数的用途。

创建一个继承于EventArgs并具有数据属性,你需要一个类:

public class HotelSelectedEventARgs : EventArgs 
{ 
    public DTOHotelInformation HotelInfo { get; set; } 
} 

然后,当你调用,而不是传递一个空的EventArgs在RowSelected处理程序,创建自定义的实例类并将所选数据分配给HotelInfo属性。