Create PopOver Without Arrows and Centered in UIViewController - ios

I am attempting to display a PopOver in the Center of the ipad in Landscape Orientation. I am able to do it now with the code below but it does not have the Properties that are associated with the "popOverViewController" that is linked up on storyboard. I want it to be a view on storyboard so that I am able to work on and edit it. As well as be able to change the size of it to be either 50% or 75% of the ipads full view and no arrow...
Please, anything will help. *Updated code....can now set size. But still not seeing the "popOverViewController" content.
self.popOverViewController = [[PopOverViewController alloc]init];
self.popOver = [[UIPopoverController alloc]
initWithContentViewController:self.popOverViewController];
CGSize size = CGSizeMake(400.0,300.0);
[self.popOver setPopoverContentSize:size];
CGRect rect = CGRectMake(self.view.frame.size.width/2, self.view.frame.size.height/2, 1, 1);
[self.popOver presentPopoverFromRect:rect inView:self.view permittedArrowDirections:0 animated:YES];

Just copy & Paste the below code
UIViewController *popovercontroller=[[UIViewController alloc] init];
UIView *popoverView=[[UIView alloc] initWithFrame:CGRectMake(312,390, 400, 344)];
popoverView.backgroundColor=[UIColor whiteColor];
popovercontroller.contentSizeForViewInPopover=CGSizeMake(400, 300);
UIDatePicker *pickerView = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 44, 400, 0)];
[pickerView setTintColor:[UIColor blackColor]];
[pickerView addTarget:self action:#selector(dueDateChanged:) forControlEvents:UIControlEventValueChanged];
pickerView.datePickerMode = UIDatePickerModeDate;
pickerView.hidden = NO;
NSString *bs ; //= [NSString alloc];
// //NSDate *newDate = [NSData alloc];
bs = CurrentSelectedDate;
if (bs.length >= 1) {
NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init] ;
// //[dateFormatter setDateStyle:NSDateFormatterLongStyle];
// [dateFormatter setTimeStyle:NSDateFormatterNoStyle];
[dateFormatter setDateFormat:#"dd-MMM-yyyy"];
// NSDate *myDate = [dateFormatter dateFromString: txtText.text];
pickerView.date = [dateFormatter dateFromString: CurrentSelectedDate];
}
else
{
pickerView.date = [NSDate date];
}
[popoverView addSubview:pickerView];
// pickerView.date = [dateFormatter dateFromString:txtText.text];
UIToolbar *pickerToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 400, 44)];
pickerToolbar.barStyle = UIBarStyleDefault;
pickerToolbar.barTintColor=[UIColor colorWithRed:150.0f/255.0f green:91.0f/255.0f blue:129.0f/255.0f alpha:1.0f];
[pickerToolbar sizeToFit];
self.navigationController.toolbar.barTintColor = [UIColor colorWithRed:150.0f/255.0f green:91.0f/255.0f blue:129.0f/255.0f alpha:1.0f];
NSMutableArray *barItems = [[NSMutableArray alloc] init];
UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:self action:nil];
[barItems addObject:flexSpace];
UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:#selector(doneButtonPressed:)];
doneBtn.tintColor=[UIColor whiteColor];
[barItems addObject:doneBtn];
UIBarButtonItem *cancelBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:#selector(cancelButtonPressed:)];
cancelBtn.tintColor=[UIColor whiteColor];
[barItems addObject:cancelBtn];
[pickerToolbar setItems:barItems animated:YES];
[popoverView addSubview:pickerToolbar];
popovercontroller.view=popoverView;
pickerViewPopup = [[UIPopoverController alloc] initWithContentViewController:popovercontroller];
[pickerViewPopup presentPopoverFromRect:CGRectMake(312, 212, 400, 344) inView:self.view permittedArrowDirections:0 animated:YES];

The reason you can't see any content is because by explicitly recreating a view controller from scratch that you already have hooked up to an outlet, the compiler assumes you'd like to trash the old value and releases the view controller instance IB created. Or, if this is a separate storyboard or XIB, then the proper initializer would be -initWithNibName:bundle:. Just omit/edit the first line, and assuming the outlets are hooked up correctly, you should see what you've put up in IB.

Alright. So I did this...
popOverViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"popOver"];

I've just been working this one out but wanted to do as much in the storyboard as possible which changes the approach a bit:
1) Select the popover in the storyboard and un-tick Directions Up/Down/Left/Right to get rid of the arrows.
To center it on screen override prepare for segue and do something like this:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
UIStoryboardPopoverSegue* popover = (UIStoryboardPopoverSegue*)segue;
CGFloat horizontalInset = (self.view.frame.size.width - popover.popoverController.popoverContentSize.width) / (CGFloat)2.0;
CGFloat verticalInset = (self.view.frame.size.height - popover.popoverController.popoverContentSize.height) / (CGFloat)2.0;
popover.popoverController.popoverLayoutMargins =
UIEdgeInsetsMake(
verticalInset,
horizontalInset,
verticalInset,
horizontalInset);
}
In my case I also found that the popover segue's corner radius didn't match my design so I change the background color to clear to sort that out i.e. add this to the above block:
popover.popoverController.backgroundColor = [UIColor clearColor];
2) In the destination controller for the segue find the attribute 'Popover' and tick 'Use Explicit Size' and put the size of you want it to appear in popover mode.

Making the background color clear almost worked for me but it messed up the grayed out background. The the part of the view that was directly behind the arrow was clear and the rest of the background way gray. So I changed the color to whatever the grayed out alpha was.
UIPopoverController *popoverController = [[UIPopoverController alloc] initWithContentViewController:newViewController];
popoverController.backgroundColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.15];

Related

UIDatePicker get .date property on "done" button press

I have a custom view with a UIDatePicker and a done button attached at the top.
When I press the done button, I would like to get the time that is in the UIDatePicker.
I receive an error when I press the button (which I expect since the sender is a UIBarButtonItem) and changing the date time works as expected.
Other solutions show separate selectors but, I would like (if possible) to call the same selector and get the selected as if it were scrolling in the picker view.
I thought of changing the selector method to receive it as an id but, that did not work.
This is what I'm doing currently, I feel like it might be something silly:
UIView *v = [[UIView alloc] init];
// Create the date time picker
CGRect pickerFrame = CGRectMake(0, 0, 320, 216);
UIDatePicker *pView = [[UIDatePicker alloc] initWithFrame:pickerFrame];
pView.datePickerMode = UIDatePickerModeTime;
[pView addTarget:self action:#selector(dateTimePickerValueChanged:) forControlEvents:UIControlEventValueChanged];
dateTimePicker = pView;
[v addSubview:dateTimePicker];
// done button
CGRect toolBarFrame = CGRectMake(0, 0, 320, 44);
UIToolbar *toolBar = [[UIToolbar alloc] initWithFrame:toolBarFrame];
UIBarButtonItem *flexibleItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithTitle:#"Done" style:UIBarButtonItemStylePlain target:self action:#selector(dateTimePickerValueChanged:)];
NSArray *toolBarItems = [NSArray arrayWithObjects:flexibleItem, doneButton, nil];
[toolBar setItems:toolBarItems];
[v addSubview:toolBar];
- (void)dateTimePickerValueChanged:(UIDatePicker *)datePicker {
NSLog(#"time on change: %#", datePicker.date);
Image reference:
Write your method without parameter and make your UIDatePicker as a property or global object for entire class so that you can access it from any where.
Now pass your method to both selectors in this way you will achieve date on done button press.
- (void)dateTimePickerValueChanged {
NSLog(#"time on change: %#", datePicker.date);
}
You're right about what's causing this to crash. I think that separating the selectors is the right path. You could have both selectors calling the same method. That way you don't have any copied code.
The correct way to do this is by creating a NSDate object which is accessible as per your requirement. Now from UIDatePicker, create a method for value changed. Whenever this method gets called set the value of date picker .date property to your NSDate object.
On press of Done button, use the value of NSDate object. It will give you the right value.
#interface ViewController(){
NSDate *globalDate;
}
#end
#implementation ViewController
- (void)dateTimePickerValueChanged {
globalDate = datePicker.date;
}
- (IBAction)donePressed {
NSLog(#"%#",globalDate);
}
#end
TIME
datePicker=[[UIDatePicker alloc]init];
datePicker.datePickerMode=UIDatePickerModeTime;
[yourField setInputView:datePicker];
UIToolbar *toolBar=[[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 44)];
[toolBar setTintColor:[UIColor grayColor]];
UIBarButtonItem *doneBtn=[[UIBarButtonItem alloc]initWithTitle:#"Done" style:UIBarButtonItemStylePlain target:self action:#selector(ShowSelectedDate)];
UIBarButtonItem *space=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
[toolBar setItems:[NSArray arrayWithObjects:space,doneBtn, nil]];
[yourField setInputAccessoryView:toolBar];
-(void)ShowSelectedDate
{
NSDateFormatter *dateFormat=[[NSDateFormatter alloc]init];
dateFormat.dateStyle=NSDateFormatterMediumStyle;
[dateFormat setDateFormat:#"hh:mm"];
NSString *str=[NSString stringWithFormat:#"%#",[dateFormat stringFromDate:datePicker.date]];
//assign text to label
yourField =str;
[yourField resignFirstResponder];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:0.5];
[UIView setAnimationBeginsFromCurrentState:YES];
self.view.frame = CGRectMake(0,0,self.view.frame.size.width, self.view.frame.size.height);
[UIView commitAnimations];
}

UIDatePicker Moving up tableview content

I have a UIViewController with a Navigation bar and also a UITableView in it. I have button in the view controller that when it is pressed pops up a UIDatePicker. However, When i press the button to pop up the UIDatePicker, all my content in the tableview moves up about 30 pixels. Not cool. I want the UIDatePicker to just popup overtop the view controller without shifting any elements. Here is the code of my date picker. Thoughts?
- (IBAction)timeWasPressed:(id)sender {
if(self.pickerShown == NO){
self.slidePicker = [[UIDatePicker alloc] init];
self.slidePicker.datePickerMode = UIDatePickerModeTime;
self.slidePicker.backgroundColor = [UIColor whiteColor];
[self.navigationController setNavigationBarHidden:YES];
[self.view addSubview:self.slidePicker];
//make done button
self.toolBar= [[UIToolbar alloc] initWithFrame:CGRectMake(0,0,320,64)];
self.toolBar.barTintColor = [UIColor whiteColor];
UIBarButtonItem *barButtonDone = [[UIBarButtonItem alloc] initWithTitle:#"Done"
style:UIBarButtonItemStylePlain target:self
action:#selector(doneButton)];
self.toolBar.items = [[NSArray alloc] initWithObjects:barButtonDone,nil];
barButtonDone.tintColor=[UIColor blackColor];
self.pickerShown = YES;
[self.view addSubview:self.toolBar];
}
}
-(void)doneButton{
NSDate *pickerDate = [self.slidePicker date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateStyle:NSDateFormatterNoStyle];
[dateFormatter setTimeStyle:NSDateFormatterShortStyle];
NSString *selectionString = [[NSString alloc] initWithFormat:#"%#", [dateFormatter stringFromDate:pickerDate]]; //
[self.timeButton setTitle:selectionString forState:UIControlStateNormal];
self.pickerShown = NO;
[self.slidePicker removeFromSuperview];
[self.toolBar removeFromSuperview];
[self.navigationController setNavigationBarHidden:NO];
}
What jason said is right, but he forgot to say you'll have to erase the line
[self.navigationController setNavigationBarHidden:YES];
And so, you'll have to replace
//....
[self.view addSubview:self.slidePicker];
//...
[self.view addSubview:self.toolBar];
//...
with
//...
[self.navigationController.view addSubview:self.slidePicker];
//...
[self.navigationController.view addSubview:self.toolBar];
//...
So your "timeWasPressed:" code will be:
self.slidePicker = [[UIDatePicker alloc] init];
self.slidePicker.datePickerMode = UIDatePickerModeTime;
self.slidePicker.backgroundColor = [UIColor whiteColor];
//[self.navigationController setNavigationBarHidden:YES];
[self.navigationController.view addSubview:self.slidePicker];
//make done button
self.toolBar= [[UIToolbar alloc] initWithFrame:CGRectMake(0,0,320,64)];
self.toolBar.barTintColor = [UIColor whiteColor];
UIBarButtonItem *barButtonDone = [[UIBarButtonItem alloc] initWithTitle:#"Done"
style:UIBarButtonItemStylePlain target:self
action:#selector(doneButton)];
self.toolBar.items = [[NSArray alloc] initWithObjects:barButtonDone,nil];
barButtonDone.tintColor=[UIColor blackColor];
self.pickerShown = YES;
[self.navigationController.view addSubview:self.toolBar];
Don't forget you can also remove the
[self.navigationController setNavigationBarHidden:NO];
from your doneButton method.
Hope that helps.
I think the reason why everything shifts up is because you are hiding the navigation bar.
[self.navigationController setNavigationBarHidden:YES];
Replace that line with the following and if you see everything animating up then this is the reason why everything is shifting.
[self.navigationController setNavigationBarHidden:true animated:true];
If you want the date picker to show over the navigation controller then instead of adding it to the view controller's view, add the picker to the navigation controller's view instead.
So.. replace
[self.view addSubview:self.slidePicker];
with..
[self.navigationController.view addSubview:self.slidePicker];
Hope it works out.

putting labels, buttons on the navigation bar iOS

I have created custom navigation controller,
I want to be added, a date at the left, a back button on the right and the title next to back button.
I tried to add one label, but it does not work. Please show me a way
UINavigationBar *naviBarObj = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, 1024, 66)];
UILabel *navLabel = [[UILabel alloc] initWithFrame:CGRectMake(20,8,280,30)];
navLabel.text = #"My Text";
[self.navigationController.navigationBar addSubview:navLabel];
[self.view addSubview:naviBarObj];
UINavigationBar *naviBarObj = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, 1024, 66)];
UILabel *navLabel = [[UILabel alloc] initWithFrame:CGRectMake(200,8,200,30)];
navLabel.text = #"My Text";
navLabel.textColor = [UIColor redColor];
[naviBarObj addSubview:navLabel];
[navLabel setBackgroundColor:[UIColor clearColor]];
[self.view addSubview:naviBarObj];
try this it will work .It works for me :)
add custom view in UIToolbar
UIToolbar *tools = [[UIToolbar alloc]
initWithFrame:CGRectMake(0.0f, 0.0f,190.0f, 44.01f)];
tools.barStyle = -1; // clear background
NSMutableArray *buttons = [[NSMutableArray alloc] init];
UIBarButtonItem *bi = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
bi.width =10.0f;
[buttons addObject:bi];
[buttons addObject:add your view];
bi = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
bi.width =10.0f;
[buttons addObject:bi];
[buttons addObject:add your view];
[tools setItems:buttons animated:NO];
UIBarButtonItem *buttons_ = [[UIBarButtonItem alloc] initWithCustomView:tools];
self.navigationItem.rightBarButtonItem = buttons_; //same to leftBarButtonItem
You can also achieve this from Interface Builder
1. First add a UIView which will look like following
2. Then add a UILabel inside the UIView which will look like following
3. In the Center It will look like following
Now add necessary constraint to meet your requirement.
You need to add navigation item to the navigation bar. One per each navigation level. So you should have at least one of them.
** update **
UINavigationItem * myNavItem = [[UINavigationItem alloc] initWithTitle:#"Some title"];
/*
* add buttons and labels
*/
[self.navigationController.navigationBar pushNavigationItem:myNavItem animated:NO];
You need to change the titleView of the topItem. Like this:
naviBarObj.topItem.titleView = navLabel;
** update: Complete code (tested and working) **
UINavigationBar *naviBar = [[UINavigationBar alloc] initWithFrame: CGRectMake(.0, .0, 320.0, 44.0)];
UINavigationItem *navItem = [[UINavigationItem alloc] init];
navItem.titleView = titleLbl;
[naviBar pushNavigationItem: navItem animated: NO];
[navItem release]; // you don't need this for ARC
[self.view addSubview: naviBar];
[naviBar release]; // you don't need this for ARC

Date and Time in UIActionsheet Picker

Hi I have a requirement where I need to show date and time in uiactionsheet on an iPad only app.
My google /sof search lead me to the following resource https://github.com/TimCinel/ActionSheetPicker
ActionSheetDatePicker *actionSheetPicker = [[ActionSheetDatePicker alloc] initWithTitle:#"" datePickerMode:UIDatePickerModeDateAndTime selectedDate:[NSDate date] target:self action:#selector(onDateSelected:element:) origin:sender];
actionSheetPicker.hideCancel = YES;
[actionSheetPicker showActionSheetPicker];
It works great except for the life of me I can't find where I can set the minimum , maximum date and intervals.
Please if any one has used this could help that be great. Thank you
Here i am using Actionsheet + UIDatePicker for iPhone/IPod, BUT for iPAD using POPOVERCONTROLLER + UIDATEPICKER.
- (IBAction)showAction:(id)sender
{
aac = [[UIActionSheet alloc] initWithTitle:#""
delegate:self
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:nil];
self.dtPicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0.0, 44.0, 0.0, 0.0)];
UIToolbar *pickerDateToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
pickerDateToolbar.barStyle = UIBarStyleBlackOpaque;
[pickerDateToolbar sizeToFit];
NSMutableArray *barItems = [[NSMutableArray alloc] init];
UIBarButtonItem *cancelBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:#selector(DatePickerCancelClick:)];
[barItems addObject:cancelBtn];
UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:#selector(DatePickerDoneClick:)];
[barItems addObject:doneBtn];
[pickerDateToolbar setItems:barItems animated:NO];
if (IS_IPHONE) {
[aac addSubview:pickerDateToolbar];
[aac addSubview:dtPicker];
[self.view addSubview:aac];
}
else {
UIView *view = [[UIView alloc] init];
[view addSubview:pickerDateToolbar];
[view addSubview:dtPicker];
UIViewController *vc = [[UIViewController alloc] init];
[vc setView:view];
[vc setContentSizeForViewInPopover:CGSizeMake(320, 260)];
popover = [[UIPopoverController alloc] initWithContentViewController:vc];
popover.delegate = self;
[popover presentPopoverFromRect:myButton.bounds inView:myButton
permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
}
//Hope you got it. Thanks
UIActionSheet *menu = [[UIActionSheet alloc] initWithTitle:#"Date Picker"
delegate:self
cancelButtonTitle:#"Cancel"
destructiveButtonTitle:nil
otherButtonTitles:nil];
// Add the picker
UIDatePicker *pickerView = [[UIDatePicker alloc] init];
pickerView.datePickerMode = UIDatePickerModeDateAndTime;
[menu addSubview:pickerView];
[menu showInView:self.view];
[menu setBounds:CGRectMake(0,0,320, 300)];
CGRect pickerRect = pickerView.bounds;
pickerRect.origin.y = -100;
pickerView.bounds = pickerRect;
Above code is useful for add UIDatePicker to UIActionSheet. In above code you can display Date and time by using UIDatePicker.
I ended up using this bit of code as per ibiren's suggestion from UIDatePicker in UIPopover thread .
UIViewController* popoverContent = [[UIViewController alloc] init]; //ViewController
UIView *popoverView = [[UIView alloc] init]; //view
popoverView.backgroundColor = [UIColor blackColor];
UIDatePicker *datePicker=[[UIDatePicker alloc]init];//Date picker
datePicker.frame=CGRectMake(0,44,320, 216);
datePicker.datePickerMode = UIDatePickerModeDateAndTime;
[datePicker setMinuteInterval:5];
[datePicker setTag:10];
[datePicker addTarget:self action:#selector(Result) forControlEvents:UIControlEventValueChanged];
[popoverView addSubview:datePicker];
popoverContent.view = popoverView;
popoverController = [[UIPopoverController alloc] initWithContentViewController:popoverContent];
popoverController.delegate=self;
[popoverContent release];
[popoverController setPopoverContentSize:CGSizeMake(320, 264) animated:NO];
[popoverController presentPopoverFromRect:tempButton.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
//tempButton.frame where you need you can put that frame
I know this answer came up late. But for anyone who would like to use this library…
The new version of ActionSheetDatePicker has the following properties:
NSDate *minimumDate;
NSInteger minuteInterval;
NSCalendar *calendar;
NSTimeZone *timeZone;
NSLocale *locale;
that allow you to modify the basic options of DatePicker as you want.

iOS Subview (UIDatePicker and UIBarButtonItem) does not respond to user input

I am fairly new to iOS programming so this might be a really simple mistake. Anyways, I have a subview which I want to appear on top of a "normal" view such that a user can input a date with a UIDatePicker and confirm his choice with a UIBarButtonItem (which will also prompt the subview to disappear) in a UIToolbar. The problem is that the control elements (Picker and Button) dont respond to tapping and other gestures despite being visible on top of the "normal" view. I noticed that a button which is part of the "normal" view responds instead, even though, this button lies beneath the subview and is not visible. Here is the code which generates the subview with its elements:
UIView * newView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 0)];
newView.backgroundColor = [UIColor colorWithWhite:1 alpha:1];
UIToolbar * toolbar = [[UIToolbar alloc] initWithFrame: CGRectMake(0, 0, 320, 49)];
toolbar.barStyle = UIBarStyleBlack;
UIBarButtonItem *infoButtonItem = [[UIBarButtonItem alloc] initWithTitle:#"Done" style:UIBarButtonItemStyleDone target:nil action:#selector(dismissCustom:)];
toolbar.items = [NSArray arrayWithObjects:infoButtonItem, nil];
UIDatePicker *datePicker = [[UIDatePicker alloc] init];
datePicker.datePickerMode = UIDatePickerModeDate;
datePicker.hidden = NO;
datePicker.date = [NSDate date];
datePicker.frame = CGRectMake(0, 49, 320, 250);
datePicker.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[datePicker addTarget:self action:#selector(pickerDateChanged:) forControlEvents:UIControlEventValueChanged];
[newView addSubview:datePicker];
[newView addSubview:toolbar];
[self.view addSubview:newView];
[self.view bringSubviewToFront:newView];
newView.tag = 1;
The methods dismissCustom: and pickerDateChanged: are as follows:
-(void)pickerDateChanged:(UIDatePicker *)sender
{
NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateStyle:NSDateFormatterMediumStyle];
[dateFormatter setTimeStyle:NSDateFormatterNoStyle];
NSLog(#"Picked the date %#", [dateFormatter stringFromDate:[sender date]]);
dateButton.titleLabel.text = [dateFormatter stringFromDate:sender.date];
}
and
-(void)dismissCustom:(UIBarButtonItem *)sender
{
UIView * newView = [[UIView alloc] viewWithTag:1];
[newView removeFromSuperview];
}
Does anybody have an idea what is missing / wrong? Any help is appreciated!
Cheers
At least for the button, you need to add a touchUpInside event for the action:
[button addTarget:self action:#selector(buttonPressed) forControlEvents:UIControlEventTouchUpInside];

Resources