Is there a way to add buttons to a UIPicker?

Discussion in 'iOS Development' started by davidlansalot, Apr 3, 2009.

  1. davidlansalot

    davidlansalot New Member

    Joined:
    Oct 29, 2007
    Messages:
    213
    Likes Received:
    0
    Device:
    2G iPod touch
    I need to add a done button to my UIPicker to make the picker exit out and return to my MainView. Can i do this by adding a done button? If so how?
  2. Cyanidepoison

    Cyanidepoison Active Member

    Joined:
    Jan 18, 2008
    Messages:
    1,076
    Likes Received:
    2
    Subclass UIPicker, add UIToolbar, put button on it that, if it is anything like a UIKeyboard, does "resignFirstResponder" so it closes.
  3. SkylarEC

    SkylarEC Super Moderator Emeritus Staff Member

    Joined:
    Sep 19, 2007
    Messages:
    6,642
    Likes Received:
    129
    Also, a UIPicker is just a fancy UITableView. Simply have it use whatever UITableCells you want. In this case, subclassed table cells that have your buttons.


    EDIT: Nevermind what I said, I didn't read your question to the end (honestly, at I didn't read it at all). Why not just have a button on screen somewhere that does what you want. Possibly in the UINavigationBar.
  4. Chicken

    Chicken Retired Moderator

    Joined:
    Feb 17, 2008
    Messages:
    2,494
    Likes Received:
    7
    Device:
    iPhone 5S
    Yeah it sounds like you're making it hard for yourself.
  5. davidlansalot

    davidlansalot New Member

    Joined:
    Oct 29, 2007
    Messages:
    213
    Likes Received:
    0
    Device:
    2G iPod touch
    alright instead of button would the UIPicker be able to close once the desired item is highlighted?
  6. Chicken

    Chicken Retired Moderator

    Joined:
    Feb 17, 2008
    Messages:
    2,494
    Likes Received:
    7
    Device:
    iPhone 5S
    Yes using the didSelectRow (I'm pretty sure that’s what it's called) method.
  7. davidlansalot

    davidlansalot New Member

    Joined:
    Oct 29, 2007
    Messages:
    213
    Likes Received:
    0
    Device:
    2G iPod touch
    Code:
    - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
    	switch (row) {
    		case 0:
    		{
    			mainImage.image = [UIImage imageNamed:@"main.gif"];
    			[myPicker resignFirstResponder];
    			break;
    
    		}
    like that?
  8. Chicken

    Chicken Retired Moderator

    Joined:
    Feb 17, 2008
    Messages:
    2,494
    Likes Received:
    7
    Device:
    iPhone 5S
    That looks right. Skylar should be able to confirm.
  9. Cyanidepoison

    Cyanidepoison Active Member

    Joined:
    Jan 18, 2008
    Messages:
    1,076
    Likes Received:
    2
    Just try it...
  10. davidlansalot

    davidlansalot New Member

    Joined:
    Oct 29, 2007
    Messages:
    213
    Likes Received:
    0
    Device:
    2G iPod touch
    well i have tried and it does not work

    EDIT: How do i assign my MainView as the first responder?

Share This Page