Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

mikezang

macrumors 6502a
Original poster
May 22, 2010
930
38
Tokyo, Japan
I use code as below to show a PickerView, but is not located at middle of center, then if I rotated, the PickerView is not to rotated, what should I have to implement for tight showing?
Code:
- (void)showPickerView {
    if (pickerView == nil) {
        pickerView = [[UIDatePicker alloc] initWithFrame: CGRectMake(0.0, 0.0, 0.0, 0.0)];
    }
	
    if (self.pickerView.superview == nil) {
        [self.view.window addSubview: self.pickerView];
		
        // size up the picker view to our screen and compute the start/end frame origin 
        // for our slide up animation compute the start frame
        CGRect screenRect = [[UIScreen mainScreen] applicationFrame];
        CGSize pickerSize = [self.pickerView sizeThatFits:CGSizeZero];
        CGRect startRect = CGRectMake(0.0, screenRect.origin.y + screenRect.size.height, pickerSize.width, pickerSize.height);
        self.pickerView.frame = startRect;
		
        // compute the end frame
        CGRect pickerRect = CGRectMake(0.0, screenRect.origin.y + screenRect.size.height - pickerSize.height, pickerSize.width, pickerSize.height);
		
        // start the slide up animation
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:0.3];
		
        // we need to perform some post operations after the animation is complete
        [UIView setAnimationDelegate:self];
		
        self.pickerView.frame = pickerRect;
		
        // shrink the table vertical size to make room for the date picker
        CGRect newFrame = detail.frame;
        newFrame.size.height -= self.pickerView.frame.size.height;
        self.detail.frame = newFrame;
        [UIView commitAnimations];
    }	
}
 

Attachments

  • SnapShot 2010-10-16 at 19.59.11.jpg
    SnapShot 2010-10-16 at 19.59.11.jpg
    60.2 KB · Views: 130
  • SnapShot 2010-10-16 at 19.59.23.jpg
    SnapShot 2010-10-16 at 19.59.23.jpg
    60.7 KB · Views: 67
I knew why PickerView is not at the center of screen, because code as below return a mistake size. I run in Portrait mode, but system gives me a Landscape width. Is this a bug in SDK?
Code:
CGSize pickerSize = [pickerView sizeThatFits:CGSizeZero];
 

Attachments

  • SnapShot 2010-10-17 at 0.46.23.jpg
    SnapShot 2010-10-17 at 0.46.23.jpg
    260.5 KB · Views: 75
I run in Portrait mode, but system gives me a Landscape width. Is this a bug in SDK?

Might be. How does the code behave on the hardware? Have you tried the iOS 4.2 beta?

Regarding centre positioning, set screenRect.size.width as the width in the startRect and pickerRect. (UIDatePicker centres itself within the given rectangle.)
 
Might be. How does the code behave on the hardware? Have you tried the iOS 4.2 beta?

Regarding centre positioning, set screenRect.size.width as the width in the startRect and pickerRect. (UIDatePicker centres itself within the given rectangle.)
I used code as below to correct miss width. Only in 4.1.
Code:
CGRect screenRect = [[UIScreen mainScreen] applicationFrame];
CGSize pickerSize = [pickerView sizeThatFits:CGSizeZero];
pickerSize.width = screenRect.size.width;

By the way, do you have any idea for rotation problem?
 
Which version of the SDK is this? ie. Why is there a window around the simulator?
You have special eyes.

I am using iOS SDK 4.1 and do my job by VNC from a ThinkPad to Mac mini.

Have you tried to use a popover? I think that is the natural human-interaction paradigm with the iPad. (I don't have an iPad.)
Can you tell me where I can find a sample for PickerView in Popover?
 

Absolutely. The fact you even question this shows that copying "sample code" and saying to yourself "I understand that" has taught you somewhere between absolutely nothing and very little. Perhaps you should accept that this approach is not working and actually sit down with a book and learn.
 
Absolutely. The fact you even question this shows that copying "sample code" and saying to yourself "I understand that" has taught you somewhere between absolutely nothing and very little. Perhaps you should accept that this approach is not working and actually sit down with a book and learn.
Your suggestion is no any suggestible all time!

You are not the Demi-God, but the God!

If anyone can do programming just read book, who needs this forum?
 
Can you tell me where I can find a sample for PickerView in Popover?

You have probably seen in the documentation that UIPopoverController is initialized with a view controller whose job is to provide the content.

Are you familiar with views and view-controllers?
 
You have probably seen in the documentation that UIPopoverController is initialized with a view controller whose job is to provide the content.

Are you familiar with views and view-controllers?
A little, though not enough. Here is found by me at first...

But I want to use a DatePicker in popover and in programming, it is not a controller so that a UIViewController might be neede.

I want to know if there is simpler way to use a DatePicker in popover, it seems like there is no such story on Internet...
 
A little, though not enough. Here is found by me at first...

But I want to use a DatePicker in popover and in programming, it is not a controller so that a UIViewController might be neede.

I want to know if there is simpler way to use a DatePicker in popover, it seems like there is no such story on Internet...

The documentation clearly states that: UIPopoverController is initialized with a view controller whose job is to provide the content.

There is no simpler way: you must create a hierarchy where there is a UIViewController which owns the UIDatePicker.
 
I thought really. I guess I was wrong.

If anyone can do programming just read book, who needs this forum?
Most of the books we talk about around here are meant to teach you the fundamentals (and not always all of them). It is then up to you, the programmer, to use your creativity and ingenuity to solve your own problems based on your knowledge of that foundation. That, to me, is where the forum comes in: when you need help for something that's beyond the basics or when writing code that applies the fundamentals but in a way unique to your specific application. Or occasionally when a fundamental confuses you and would like it explained in a different manner.

A little, though not enough.
I would take this as your cue then to go learn enough about how views and viewcontrollers work.

Also, remember that an important skill (probably the most important) of programming is being able to take a larger problem and divide it into smaller problems, sometimes called "divide-and-conquer", which you solve individually and then piece together.

So, for example, for your recent problem, I would break it down into:
1) how do I add a date picker to a view that has a viewcontroller
2) how do I take a view, any view, that has a viewcontroller and present it from within a popover controller

Then, it's just a matter of combining 1) and 2). Not always is this an easy thing but in this case, I think it's fairly trivial.

Hope that helps.
 
I thought really. I guess I was wrong.


Most of the books we talk about around here are meant to teach you the fundamentals (and not always all of them). It is then up to you, the programmer, to use your creativity and ingenuity to solve your own problems based on your knowledge of that foundation. That, to me, is where the forum comes in: when you need help for something that's beyond the basics or when writing code that applies the fundamentals but in a way unique to your specific application. Or occasionally when a fundamental confuses you and would like it explained in a different manner.


I would take this as your cue then to go learn enough about how views and viewcontrollers work.

Also, remember that an important skill (probably the most important) of programming is being able to take a larger problem and divide it into smaller problems, sometimes called "divide-and-conquer", which you solve individually and then piece together.

So, for example, for your recent problem, I would break it down into:
1) how do I add a date picker to a view that has a viewcontroller
2) how do I take a view, any view, that has a viewcontroller and present it from within a popover controller

Then, it's just a matter of combining 1) and 2). Not always is this an easy thing but in this case, I think it's fairly trivial.

Hope that helps.
Thanks for your suggestion.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.