简体   繁体   中英

UIActionSheet with UIPickerView and Done, Next, Previous buttons

i am trying to implement an action sheet that contains a picker view and a segmented control bar with a previous button, next button and done button like the image as follows http://imgur.com/8wVMy . I currently am able to make it look like this http://imgur.com/AXn6H . I was wondering if someone could help me get the picker view to sit on the bottom and just make it look a little better. Thanks for any help.

Unless you're targeting very old versions of iOS (ie versions earlier than 3.2), the best way to do it is to take a completely different approach.

As of 3.2, any UIResponder (which includes all UIViews) can return a UIView from its inputView property to show that view instead of the keyboard when the view becomes the first responder. This even works for views that normally don't become first responder or don't display the keyboard at all. It's simple:

  1. Design your popup view, as you would any other view.
  2. Ensure that your widget view returns YES from canBecomeFirstResponder .
  3. Ensure that your widget view returns an instance of your popup view from inputView .

More details are available in the documentation .

Also, BTW, if you're on an iPad you should probably use a UIPopoverController to display a UIPickerView instead of either of these methods. Apple may actually require this if you intend to get your app in the app store.

The next and previous buttons are actually showing your images to segmentedController Within a toolbar. To get it You have to define the segmentedController and UIToolbar on. H. Next add the DataSource and UIPickerView Then in the viewDidLoad create objects and define Their properties. For example:

 if (keyboardToolbar == nil) {
        keyboardToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 44)];
        [keyboardToolbar setBarStyle:UIBarStyleBlackTranslucent];


        segControl = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"Anterior", @"Siguiente", nil]];
        [segControl setSegmentedControlStyle:UISegmentedControlStyleBar];
        [segControl setTintColor:[UIColor blackColor]];
        segControl.frame = CGRectMake(5, 7, 150, 33);
        segControl.momentary = YES;
        [segControl addTarget:self action:@selector(segSelected:) forControlEvents:UIControlEventValueChanged];

        UIBarButtonItem *extraSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];

        UIBarButtonItem *aceptar = [[UIBarButtonItem alloc] initWithTitle:@"Hecho" style:UIBarButtonItemStyleDone target:self action:@selector(cerrarTeclado:)];

        //aceptar.width = 70.0f;

        [keyboardToolbar setItems:[[NSArray alloc] initWithObjects: extraSpace, aceptar, nil]];
        [keyboardToolbar addSubview:segControl];
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM