Search code examples
ipadc#-4.0uitableviewxamarin.iosuipickerview

how to add a uipickerview as a sub view in a uitableviewcell using monotouch?


  • I have implemented a grid-looking structure (say 5 rows and 10 columns) for an iPad. I have done this by adding many UITextFileds(by creating Frames) as subviews(each cell being editable, just like an excel sheet) in a single row of a UItableViewCell.

  • Now my task is to have a pull/drop down menu when the user clicks on any cell.I found this a difficult to implement, as I am new to monotouch. So I decided to go for the default UIPicker(drum like structure).

  • So this is what I want to achieve now, when the user clicks on the cell in the lower half of the screen of the iPad I would want the picker element(the drum) to show up and the user could click on the value to choose a value (different fields may have a different range of values).

  • BottomLine I want to add UIPicker to a UItableViewcell using monotouch(N.B. Normal procedure using monotouch dialog declares picker elements in a section under a rootelement, I can't do that here I guess.)

So Kindly tell me how to go about it,or if there is any better way to achieve this drop-down experience keeping the grid intact.Thanks in advance!


Solution

  • For item 3 in your list: you could use UIPopoverController on a iPad, in which you could place UIPicker or any other controls. Demo: https://github.com/xamarin/monotouch-samples/tree/master/Popovers will help you.

    Screenshot of demo

    You could fire UIPopoverController in UITableViewSource (UITableViewDelegate) subclass on RowSelected event.

    For item 4 in your list: if you want to add UIPicker right in a UITableViewCell, for example, in the last one, you should do such things:

    • Declare your own UITableViewCell subclass, which creates UIPicker within itself;
    • On UITableView.GetCell event check that indexPath points to last one cell. If so, create your custom UITableViewCell.