1

I need to load a view based on [PickerView didSelectRow:(NSInteger)row inComponent(NSInteger)component]

I have the highlight and selection logic figured out, what I need now is just a simple way of determining if the select button has been pressed to load the view.

Is this possible?

For example,

if ( /* select button is pressed */ )
{
    //push selected view onto stack.
}

Update

Here, I'll post code so you can see what I have going. I have most everything setup via nib files.

-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {

    /* 
    //do simple error checking to ensure nothing badly crazy happens

    if(row > [mPickerMenuItems count])
    {
        NSLog(@"Row index is out of bounds of mPickerMenuItems length in [Overview pickerView:(UIPickerView*) didSelectRow:(NSInteger) inComponent:(NSInteger)]...bailing out");

        return;
    }
    else if(row < 0)
    {
        NSLog(@"Row index is negative in [Overview pickerView:(UIPickerView*) didSelectRow:(NSInteger) inComponent:(NSInteger)]...bailing out.");

        return;
    }
    */

    NSString* selected = [_pickerMenuItems objectAtIndex:row];

    //NSLog(@"(in [Overview pickerView: didSelectRow]) resultLabel.text => %@", mResultLabel.description);

    if([selected isEqualToString:@"My Profile"])
    {

        if ( /* select button is pressed */ )
        {
            //push view onto stack.
        }

        NSLog(@"My Profile has been selected");
    }
    else if([selected isEqualToString:@"Services"])
    {

        NSLog(@"Services has been selected");
    }
    else if([selected isEqualToString:@"Tools"])
    {

        NSLog(@"Tools has been selected");
    }
    else if([selected isEqualToString:@"Media"])
    {

        NSLog(@"Media has been selected");
    }
    else
    {
        NSLog(@"Nothing has been selected in [Overview pickerView: didSelectRow]");
    }
}

Update 2

Sorry for the confusion. I guess what I should say is that I want to fire the view switch as soon as the UIBarButtonItem is selected, based on the on the item highlighted in the UIPickerView. I'm pretty sure if I went with the natural choice of just using the method I have and if-elseing it all, it would switch and load, but NOT when the select button is pressed.

How is this done?

zeboidlund
  • 9,731
  • 31
  • 118
  • 180

2 Answers2

2

You just need to add a target to it? Or am I missing something?

UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:@"My Bar Button" style:UIBarButtonItemStyleBordered target:self action:@selector(MYMETHOD)];
Ryan Poolos
  • 18,421
  • 4
  • 65
  • 98
  • I'll be completely honest I am still lost. Can you update your post with a little more description of what you're doing and trying to do? If you've made a select button you just need a target for it. – Ryan Poolos Aug 16 '12 at 20:15
  • You can set the target via the xib also, by selecting the button, going to the connections inspector, and dragging from one of the circles under "Send Events" to the method you want called when the event fires. (Usually you would use the Touch Up Inside event.) You can even drag from the circle to your header file if it's visible, and it'll create a new method to receive the event for you. Pretty slick, IMO. – livingtech Aug 16 '12 at 20:17
  • Updated question. @livingtech, given my recent update on the question, is what I want to do possible via that method? – zeboidlund Aug 16 '12 at 20:21
  • Ok based on what you've said in the update you need to do just what I said. Add a selector to your select button that loads your next view with whatever is selected in your pickerView – Ryan Poolos Aug 16 '12 at 20:32
  • @aboutblank I think what you need to do then is keep track of your selection via a new property or something. Then create a new method like I suggested, and when it fires, push the view controller based on your property. – livingtech Sep 20 '12 at 21:24
0
- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component 

is called when a particular object is slected in the picker view.

Assuming that the _pickerview is your data source for the picker view you can simply load the view you want to based on the selected index.

if(indexPath.row == x){
//Code to bring up the view controller
}

Your question is confusing and not clear what you want to do. if that answers your question fine or clarify what is it that you want to achieve

LostPuppy
  • 2,471
  • 4
  • 23
  • 34