hackiftekhar / IQActionSheetPickerView

ActionSheet with UIPickerView
MIT License
205 stars 76 forks source link

iOS 8 #6

Closed Knodd closed 10 years ago

Knodd commented 10 years ago

Doesn't work in iOS 8... The only thing that shows up is the Picker title

mevansjr commented 10 years ago

Is there a fix for this?

zhouyuan24 commented 10 years ago

ios8 don`t support

Knodd commented 10 years ago

Found out that in iOS 8 you`re not allowed to put a pickerview inside an action sheet. You need to put your pickerview in an UIView and present it modally. I tried to convert IQActionSheetPickerView from action sheet to UIView, but after an hour I ended up moving my pickerviews into my main viewcontroller class and handle everthing there.

mevansjr commented 10 years ago

Could you give me an code-example of how you did this? Much appreciated .. Thanks in advance.

On Mon, Sep 1, 2014 at 7:24 AM, Knodd notifications@github.com wrote:

Found out that in iOS 8 you`re not allowed to put a pickerview inside an action sheet. You need to put your pickerview in an UIView and present it modally. I tried to convert IQActionSheetPickerView from action sheet to UIView, but after an hour I ended up moving my pickerviews into my main viewcontroller class and handle everthing there.

— Reply to this email directly or view it on GitHub https://github.com/hackiftekhar/IQActionSheetPickerView/issues/6#issuecomment-54048610 .

Knodd commented 10 years ago

I moved all functions for pickerview into my main class that I was calling IQActionSheetPickerView from and inserted the data directly into the functions. Then I created a view and animated it onto the screen

.h-file contains NSArray YOURDATAARRAY; @interface MapViewController : UIViewController <UIPickerViewDataSource,UIPickerViewDelegate>{ UIView ViewForPickerView; UIPickerView valuePicker; UIToolbar pickerViewToolBar; }

.m-file contains -(void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib

//Set up arrays for pickerview
YOURDATAARRAY = [NSArray arrayWithObjects:@"one", @"two", @"three", @"four", nil];

}

-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{ return 1; }

-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{ return YOURDATAARRAY.count; }

-(NSString )pickerView:(UIPickerView )pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{ return [YOURDATAARRAY objectAtIndex:row]; }

-(void)showPickerView{ //if pickerview is already loaded, animate view off screen and remove if (ViewForPickerView!=nil) { [ViewForPickerView removeFromSuperview]; }

//set up pickerview
ViewForPickerView = [[UIView alloc]initWithFrame:CGRectMake(0, self.view.bounds.size.height, self.view.bounds.size.width, 266)];

pickerViewToolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
pickerViewToolBar.barStyle = UIBarStyleDefault;//UIBarStyleBlackTranslucent;
[pickerViewToolBar sizeToFit];

UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(pickerViewCancel:)];

UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(pickerViewDone:)];

[pickerViewToolBar setItems:[NSArray arrayWithObjects:cancelButton,flexSpace,doneBtn, nil] animated:YES];
[ViewForPickerView addSubview:pickerViewToolBar];

valuePicker = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 44, 320, 216)];
valuePicker.backgroundColor = [UIColor whiteColor];
valuePicker.delegate=self;
valuePicker.dataSource=self;
valuePicker.showsSelectionIndicator=YES;
[valuePicker selectRow:0 inComponent:0 animated:NO];

[ViewForPickerView addSubview:valuePicker];

[self.view addSubview:ViewForPickerView];

[UIView animateWithDuration:0.3 animations:^{ViewForPickerView.frame = CGRectMake(0, self.view.bounds.size.height-266+16, self.view.bounds.size.width, 266);}];

}

-(void)pickerViewDone:(UIBarButtonItem)barButton{ NSMutableArray selectedTitles = [[NSMutableArray alloc] init];

    NSInteger row = [valuePicker selectedRowInComponent:0];

    if (row!= -1)
    {
        [selectedTitles addObject:[YOURDATAARRAY objectAtIndex:row]];
        DataReciever = [YOURDATAARRAY objectAtIndex:row]
    else
    {
        [selectedTitles addObject:[NSNull null]];
    }
//animate view off screen and remove
[UIView animateWithDuration:0.3 animations:^{ViewForPickerView.frame = CGRectMake(0, self.view.frame.size.height, self.view.bounds.size.width, 266);} completion:^(BOOL finished){[ViewForPickerView removeFromSuperview];}];

}

-(void)pickerViewCancel:(UIBarButtonItem*)barButton{ //animate view off screen and remove [UIView animateWithDuration:0.3 animations:^{ViewForPickerView.frame = CGRectMake(0, self.view.frame.size.height, self.view.bounds.size.width, 266);} completion:^(BOOL finished){[ViewForPickerView removeFromSuperview];}]; }

Hope this helps. I was hinking of converting it to a component and putting it on github, but I don't know if I'll have the time anytime soon :-)

Knodd commented 10 years ago

Some became code and some not... enclosing text in ` removed all line breaks so It was very hard to read. Anybody know how to paste code blocks and keep formatting?

LordZQXP commented 10 years ago

Here is an easier solution to this problem. Use IBActionSheet found here: https://github.com/ianb821/IBActionSheet Then in IQActionSheetPickerView.h replace the UIActionSheet with IBActionSheet.

edison9888 commented 10 years ago

hi,ios8 don`t support.

AleksBidnik commented 10 years ago

KnightMDT, your approach doesn't work for me. Action sheet still init only with title, without content. =( Now I try approach of Knodd.

hackiftekhar commented 10 years ago

Fixed CGContextWarnings. Updated to support iOS 8. Internal architecture updated.