0

I have this method to create an action sheet and uipicker:

-(void)presentNewPicker{
    self.aac = [[UIActionSheet alloc] initWithTitle:@"What City?"
                                                     delegate:self
                                            cancelButtonTitle:nil
                                       destructiveButtonTitle:nil
                                            otherButtonTitles:@"OK", nil];


    self.pickrView = [[UIPickerView alloc] initWithFrame:CGRectMake(0.0, 44.0, 0.0, 0.0)];
    self.pickrView.showsSelectionIndicator = YES;
    self.pickrView.dataSource = self;
    self.pickrView.delegate = self;

    self.cityNames = [[NSArray alloc] initWithObjects: @"Phoenix", @"Tahoe", @"Nevada", @"Lime", @"Florida", nil];

    UIToolbar *pickerDateToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
    pickerDateToolbar.barStyle = UIBarStyleBlackOpaque;
    [pickerDateToolbar sizeToFit];

    NSMutableArray *barItems = [[NSMutableArray alloc] init];

    UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
    [barItems addObject:flexSpace];

    UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(dismissActionSheet:)];

    [barItems addObject:doneBtn];

    [pickerDateToolbar setItems:barItems animated:YES];

    [self.aac addSubview:pickerDateToolbar];


    [self.aac addSubview:self.pickrView];
    [self.aac showInView:self.view];
    [self.aac setBounds:CGRectMake(0,0,320, 464)];
}

The button that appears reads DONE but I want to modify it to read, Ready. How do I accomplish this?

marciokoko
  • 4,988
  • 8
  • 51
  • 91
  • This is a total misuse of `UIActionSheet`. A `UIActionSheet` is only to be used to show a set of buttons. That's it. Doing what you are doing is likely to break in a future update to iOS. – rmaddy Aug 07 '13 at 22:46
  • @rmaddy Well I actually got that code from SO. What would you suggest to display a UIPickerView within the same view? – marciokoko Aug 07 '13 at 22:48
  • Create your own view with the picker and other buttons. Then do your own animation to display and dismiss the view. – rmaddy Aug 07 '13 at 22:49
  • And I would do that by creating a uiview, placing it at the bottom, adding a toolbar over it with the button, adding the uipicker to that new uiview and simply adding its height to its position in order to have it move down and out of the screen, sorta-thing? :) – marciokoko Aug 07 '13 at 22:51
  • That sounds about right. – rmaddy Aug 07 '13 at 22:52
  • Maybe you'd be interested in BlocksKit. In the library, there is a really versatile UIActionSheet+BlocksKit. https://github.com/pandamonia/BlocksKit – jakenberg Aug 07 '13 at 22:58

2 Answers2

1

Replace:

UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(dismissActionSheet:)];

with:

UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc] initWithTitle:@"Ready" style: UIBarButtonItemStyleBordered target:self action:@selector(dismissActionSheet:)];

You may want to use UIBarButtonItemStyleDone for the style.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
1

I don't know what you want to do, but you might be interested in using the inputView and inputAccessoryView for one of your uiviews, to replace the keyboard. That'll give you the animations for free, and a place to put a toolbar. Some answers that might help: https://stackoverflow.com/a/6075062/220820
https://stackoverflow.com/a/8583703/220820

Community
  • 1
  • 1
Andreas
  • 2,665
  • 2
  • 29
  • 38