ios - MONOTOUCH open a viewcontroller on tableview cell is clicked -


i have following viewcontroller tableview , custom cell:

using system; using system.drawing; using monotouch.foundation; using monotouch.uikit; using system.linq; using system.threading; using system.data; using system.io; using mono.data.sqlite; using system.collections.generic; using zurfers.mobile.core; using alextouch.mbprogresshud; using system.collections;  namespace zurfers.mobile.ios {     public partial class iphonehotelsearchviewcontroller : uiviewcontroller     {          mbprogresshud hud;          public string destination {             get;             set;         }          public datetime checkindate {             get;             set;         }          public datetime checkoutdate {             get;             set;         }          public int rooms {             get;             set;         }             public iphonehotelsearchviewcontroller (intptr handle) : base (handle)         {          }          public override void viewdidload ()         {             base.viewdidload ();              hud = new mbprogresshud(this.view);             hud.mode = mbprogresshudmode.indeterminate;             hud.labeltext = "loading...";             hud.detailslabeltext = "searching hotel";             this.view.addsubview(hud);             hud.show(true);          }          public override void viewdidappear (bool animated) {             base.viewdidappear (animated);             searchhotel ();          }          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);               list<dtohotelinformation> 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();          }          partial void goback (monotouch.foundation.nsobject sender)         {             dismissviewcontroller(true, null);         }     } } 

now table source

using system; using monotouch.foundation; using monotouch.uikit;  namespace zurfers.mobile.ios {     public class hoteltablesource : uitableviewsource     {          dtohotelinformation[] tableitems;         nsstring cellidentifier = new nsstring("tablecell");            public hoteltablesource (dtohotelinformation[] items)         {             tableitems = items;         }         public override int rowsinsection (uitableview tableview, int section)         {             return tableitems.length;         }          public override void rowselected (uitableview tableview, nsindexpath indexpath)         {             //what here              tableview.deselectrow (indexpath, true); // normal ios behaviour remove blue highlight         }          public override uitableviewcell getcell (uitableview tableview, monotouch.foundation.nsindexpath indexpath)         {             customcell cell = tableview.dequeuereusablecell(cellidentifier) customcell;              if (cell == null)                 cell = new customcell(cellidentifier);             cell.updatecell(tableitems[indexpath.row].title, tableitems[indexpath.row].subtitle, tableitems[indexpath.row].price,                             tableitems[indexpath.row].imageulr, tableitems[indexpath.row].rating );             return cell;          }          public override float getheightforrow(uitableview tableview, nsindexpath indexpath)         {             return 70;         }     } } 

finally customcell code:

using system; using system.drawing; using monotouch.foundation; using monotouch.uikit; using monotouch.dialog.utilities;  namespace zurfers.mobile.ios {     public class customcell : uitableviewcell, iimageupdated     {         uilabel headinglabel, subheadinglabel, pricelabel;         uiimageview imageservice;         uiimageview star, star2, star3, star4, star5;         public customcell (nsstring cellid) : base (uitableviewcellstyle.default, cellid)         {             imageservice = new uiimageview();             star   = new uiimageview();             star2  = new uiimageview();             star3  = new uiimageview();             star4  = new uiimageview();             star5  = new uiimageview();             headinglabel = new uilabel(){                 font = uifont.fromname("verdana-bold", 14f),                 backgroundcolor = uicolor.clear,                 textcolor = uicolor.fromrgb(241, 241, 211)             };             subheadinglabel = new uilabel(){                 font = uifont.fromname("verdana-bold", 8f),                 textcolor = uicolor.fromrgb(255, 255, 255),                 backgroundcolor = uicolor.clear             };             pricelabel = new uilabel(){                 font = uifont.fromname("verdana", 14f),                 textcolor = uicolor.fromrgb(241, 241, 211),                 backgroundcolor = uicolor.clear             };              addsubview(imageservice);             addsubview(headinglabel);             addsubview(subheadinglabel);             addsubview(pricelabel);             addsubview(star);             addsubview(star2);             addsubview(star3);             addsubview(star4);             addsubview(star5);          }          public void updatecell (string title, string subtitle, string price, string imageulr, string rating )         {             if (imageulr != null) {                 var u = new uri(imageulr);                 imageloader myloader= new imageloader(50,50);                 imageservice.image = myloader.requestimage(u,this);              } else {                 imageservice.image = uiimage.fromfile("generic_no_image_tiny.jpg");             }               headinglabel.text = title;             subheadinglabel.text = subtitle;             if (subtitle.length > 40) {                 subheadinglabel.linebreakmode = uilinebreakmode.wordwrap;                 subheadinglabel.lines = 0;             }              switch (rating) {                 case "t":                     star.image = uiimage.fromfile("zurfersmovil-stars.png");                     star2.image = uiimage.fromfile("zurfersmovil-stars.png");                     break;                 case "s":                     star.image = uiimage.fromfile("zurfersmovil-stars.png");                     star2.image = uiimage.fromfile("zurfersmovil-stars.png");                     star3.image = uiimage.fromfile("zurfersmovil-stars.png");                     break;                 case "f":                     star.image = uiimage.fromfile("zurfersmovil-stars.png");                     star2.image = uiimage.fromfile("zurfersmovil-stars.png");                     star3.image = uiimage.fromfile("zurfersmovil-stars.png");                     star4.image = uiimage.fromfile("zurfersmovil-stars.png");                     break;                 case "l":                     star.image = uiimage.fromfile("zurfersmovil-stars.png");                     star2.image = uiimage.fromfile("zurfersmovil-stars.png");                     star3.image = uiimage.fromfile("zurfersmovil-stars.png");                     star4.image = uiimage.fromfile("zurfersmovil-stars.png");                     star5.image = uiimage.fromfile("zurfersmovil-stars.png");                     break;             }               pricelabel.text = "usd " + price;             pricelabel.font = uifont.boldsystemfontofsize (16);         }           public void updatedimage (uri uri)         {             imageservice.image = imageloader.defaultrequestimage(uri, this);         }           public override void layoutsubviews ()         {             base.layoutsubviews ();             imageservice.frame = new rectanglef(10, 10, 50, 33);             headinglabel.frame = new rectanglef(70, 4, 240, 25);             subheadinglabel.frame = new rectanglef(70, 25, 240, 20);             pricelabel.frame = new rectanglef(220, 45, 100, 20);             star.frame = new rectanglef(70, 45, 15, 15);             star2.frame = new rectanglef(85, 45, 15, 15);             star3.frame = new rectanglef(100, 45, 15, 15);             star4.frame = new rectanglef(115, 45, 15, 15);             star5.frame = new rectanglef(130, 45, 15, 15);         }     } } 

i want open viewcontroller (iphonehoteldetailviewcontroller) when user touch cell of table view. don not have idea of how this.

could me please.

thanks in advance help.

generally, want navigationcontroller "top" element in app, wrapping other controllers.

in appdelegate, create navigationcontroller, , make root of application.

then create instance of search controller , push onto navigationcontroller.

finally, add navigationcontroller property constructor of tablesource.

navigationcontroller nav;  public hoteltablesource (dtohotelinformation[] items, navigationcontroller nav) {    this.nav = nav;    tableitems = items; } 

when create tablesource, pass navigationcontroller reference in. can because viewcontrollers have property points navigationcontroller, if contained within one.

hotelsearchtable.source = new hoteltablesource(data.toarray(), this.navigationcontroller); 

finally, in rowselected, create instance of new viewcontroller want display:

    public override void rowselected (uitableview tableview, nsindexpath indexpath)     {         //what here         mydetailcontroller mydetail = new mydetailcontroller();         nav.pushviewcontroller(mydetail, true);          tableview.deselectrow (indexpath, true); // normal ios behaviour remove blue highlight     } 

Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -