uiscrollview rest when touch - objective-c

i have UIScrollView it has next button when click it run this code
-(IBAction)ScrollPage:(id)sender {
NSLog(#"ScrollPage Called");
NSInteger positionX;
if ([sender tag] == 1) {
positionX = AddNewScroll.contentOffset.x - 320;
}else {
positionX = AddNewScroll.contentOffset.x + 320;
}
[AddNewScroll setContentOffset:CGPointMake(positionX,0) animated:YES];
}
and it will move the scroll to new page , then i have button there when click it will call
-(IBAction)SelectImg:(id)sender {
UIActionSheet *imgMenu = [[UIActionSheet alloc] initWithTitle:#"choose image"
delegate:self
cancelButtonTitle:#"Cancel"
destructiveButtonTitle:#"Camera"
otherButtonTitles:#"Album",nil];
imgMenu.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
[imgMenu showInView:[UIApplication sharedApplication].keyWindow];
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
imgPicker = [[UIImagePickerController alloc] init];
imgPicker.allowsEditing = YES;
imgPicker.delegate = self;
#try {
if (buttonIndex == 0) {
imgPicker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController:imgPicker animated:YES];
}
if (buttonIndex == 1) {
imgPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
//Start iPhone PhotoLibrary
if ([[UIDevice currentDevice]userInterfaceIdiom] == UIUserInterfaceIdiomPhone){
[self presentModalViewController:imgPicker animated:YES];
} else
//Start iPad PhotoLibrary
if ([[UIDevice currentDevice]userInterfaceIdiom] == UIUserInterfaceIdiomPad){
aPopover = [[UIPopoverController alloc] initWithContentViewController:imgPicker];
[aPopover presentPopoverFromRect:CGRectMake(250, 40, 300, 300) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
}
}
the Problem is when it call the actionSheet the UIScrollView by itself go to first page contentOffset to 0 then call scrollViewDidScroll
ps. Paging Disable

In the method clickedButtonAtIndex, you are re-allocating your UIImagePickerController. Isn't that the reason why it goes back to 0?
Also, what relation is there between AddNewScroll and imgPicker?

Related

Back animation transition strange in UINavigationController?

I got one Problem in my iphone app. I m developing UISlitViewcontroller with multiple detailview controller. All works well but one of my detailviewcontroller want to push more viewcontroller on particular detailview. Pusp and pop works well. while push the transition animation works well but while pop the transition not works.. Here is my code below.. Please tell solution for my problem.
//In app delegate i initialize my splitviewcontroller...
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.rootVC = [[MasterViewController1 alloc]init];
self.detailVC = [[DetailViewController alloc]init];
UINavigationController *DetailNav = [[UINavigationController alloc]initWithRootViewController:self.detailVC];
SplitVC = [[UISplitViewController alloc]init];
SplitVC.viewControllers = [[NSArray alloc]initWithObjects:self.rootVC, DetailNav, nil];
SplitVC.delegate = self.detailVC;
self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
self.window.rootViewController = SplitVC;
[self.window makeKeyAndVisible];
return YES;
}
//In Master view I use mutiple viewcontroller like this
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSUInteger row = indexPath.row;
[self.appDelegate.SplitVC viewWillDisappear:YES];
NSMutableArray *viewControllerArray=[[NSMutableArray alloc] initWithArray:[[self.appDelegate.SplitVC.viewControllers objectAtIndex:1] viewControllers]];
[viewControllerArray removeLastObject];
if (row == 0)
{
self.detailViewController = [[DetailViewController alloc] init];
[viewControllerArray addObject:self.detailViewController];
self.detailViewController.detailItem = self.detailViewController;
self.appDelegate.SplitVC.delegate = self.detailViewController;
}
if (row == 1)
{
self.currencyVC = [[CurrencyConvertorViewController alloc]init];
[viewControllerArray addObject:self.currencyVC];
self.currencyVC.detailItem = self.currencyVC;
self.appDelegate.SplitVC.delegate = self.currencyVC;
}
if (row == 2)
{
self.latest = [[PhoneExample alloc]init];
[viewControllerArray addObject:self.latest];
self.latest.detailItem = self.latest;
self.appDelegate.SplitVC.delegate = self.latest;
}
if (row == 3)
{
self.settingsVC = [[SettingPage alloc]init];
[viewControllerArray addObject:self.settingsVC];
self.settingsVC.detailItem = self.settingsVC;
self.appDelegate.SplitVC.delegate = self.settingsVC;
}
[[self.appDelegate.SplitVC.viewControllers objectAtIndex:1] setViewControllers:viewControllerArray animated:NO];
[self.appDelegate.SplitVC viewWillAppear:YES];
}
In one of my Detail view controller I pushing anotherview controller in same Master selected row Viewcontroller like this
-
(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
LatestVersionMobileViewController *phone_version = [[LatestVersionMobileViewController alloc]init];
phone_version.phone = [phone_types objectAtIndex:indexPath.row];
self.title = #"Phones";
[self.navigationController pushViewController:phone_version animated:YES];
}
Then UserOrientation like this..
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Overriden to allow any orientation.
if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
[[self navigationItem] setLeftBarButtonItem:nil];
CGRect frame1 = CGRectMake(0, 0, 700, 768);
self.view.frame = frame1;
frame1.size.width = frame1.size.width + 10;
myTable.frame = frame1;
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
else
{
[[self navigationItem] setLeftBarButtonItem:self.appDelegate.rootPopoverButtonItem];
frame.origin.x = 0;
frame.origin.y = 0;
self.view.frame = frame;
myTable.frame = frame;
return interfaceOrientation == UIInterfaceOrientationPortrait;
}
}

popViewControllerAnimated affects viewwillappear?

I have two classes. lets say A,B Classes. from A class pushviewController is called, then B class will appear. Then here is the problem .when i call popviewcontrolleranimated method from B class it is going back to A, but then both class`s viewwillappear method is being called. so anyone can tell me what is going on in here. i am stuck!.
Below is the A class.
#implementation ShakeViewController
- (id) init {
if (self = [super init]) {
movieName = #"04";
self.view = [[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease];
[self.view setBackgroundColor:[UIColor whiteColor]];
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"shake_it.png"]];
[self.view addSubview:imageView];
[imageView release];
nextController = [[OtsugeViewController alloc] init];
}
return self;
}
- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration {
const float violence = 1.2;
static BOOL beenhere;
BOOL shake = FALSE;
if (beenhere) return;
beenhere = TRUE;
if (acceleration.x > violence || acceleration.x < (-1* violence))
shake = TRUE;
if (acceleration.y > violence || acceleration.y < (-1* violence))
shake = TRUE;
if (acceleration.z > violence || acceleration.z < (-1* violence))
shake = TRUE;
if (shake && mPlayerPushed) {
[self playSound:#"suzu"];
if ([[NSUserDefaults standardUserDefaults] boolForKey:#"noVib"] == NO) {
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
}
[[UIAccelerometer sharedAccelerometer] setDelegate:nil];
[self presentModalViewController:mMoviePlayer animated:YES];
[self play];
mPlayerPushed = YES;
}
beenhere = false;
}
- (void)toNext {
NSLog(#"ShakeViewController:toNext");
[self.navigationController pushViewController:nextController animated:NO];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
NSLog(#"Shake:viewWillAppear");
}
- (void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
[[UIAccelerometer sharedAccelerometer] setDelegate:self];
[[UIAccelerometer sharedAccelerometer] setUpdateInterval:0.5];
}
- (void)dealloc {
[super dealloc];
}
#end
here is B class
#implementation OtsugeViewController
- (id) init {
if (self = [super init]) {
movieName = #"03";
self.view = [[[OtsugeView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease];
}
return self;
}
- (void) toNext {
NSLog(#"OtsugeViewController:toNext");
[self.navigationController popViewControllerAnimated:NO];
}
- (void) toToppage
{
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:NO];
[self.navigationController popToRootViewControllerAnimated:NO];
}
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(#"Screen touch Otsuge View");
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil
delegate:self
cancelButtonTitle:#"Cancel" destructiveButtonTitle:nil
otherButtonTitles:#"Retry", #"Main Menu", nil];
actionSheet.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
actionSheet.cancelButtonIndex = 0;
[actionSheet showInView:self.view];
[actionSheet release];
}
- (void) actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex: (NSInteger)buttonIndex
{
switch (buttonIndex) {
case 0: // Retry
[self presentModalViewController:mMoviePlayer animated:YES];
[self play];
break;
case 1: // Main Menu
[self toToppage];
break;
case 2: // Cancel
break;
default:
break;
}
}
- (void) viewWillAppear:(BOOL)animated {
mMoviePlayer.moviePlayer.backgroundView.backgroundColor = [UIColor blackColor];
[self playSound:#"taiko_1"];
NSLog(#"Otsuge:viewWillAppear");
[(OtsugeView *)self.view renewImageView];
[super viewWillAppear:animated];
}
- (void) viewDidAppear:(BOOL)animated{
NSLog(#"Otsuge:viewDidAppear");
[super viewDidAppear:animated];
}
- (void) dealloc {
[super dealloc];
}
#end
It's normal. View will appear is called each time a view will appear. If you want to call a method only when the view appears for the first time use -viewdidload because in a view controller each view that is in the stack is kept in memory but those you pop get deallocated.

Xcode Error With More Than 5 UIImages [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
iPhone, “More than maximum 5 filtered album lists trying to register. This will fail.” Error
When I'm adding images to UIImageViews via Popover Controller or Modal View Controller, after the 4th image, when I go to add the 5th, Xcode's debugger outputs: "Error: More than maximum 5 filtered album lists trying to register. This will fail." It will still let me add in 5+ pictures, but only 4 of them save. I've done some research on here about this, and found this question:
iOS 5 GM: <Error>: More than maximum 5 filtered album lists trying to register. This will fail
The answer in here appears as though it is a bug with Apple, and that it should be ignored. Well, Apple is usually (somewhat) quick about fixing their Xcode bugs, and this has been around for a while, so I'm starting to wonder what the real cause is. I think this error is related to my app only saving up to 4 of the pictures.
Here is the code I'm working with:
- (IBAction)grabImage {
self.imgPicker = [[UIImagePickerController alloc] init];
self.imgPicker.delegate = self;
self.imgPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
_popover = [[UIPopoverController alloc] initWithContentViewController:imgPicker];
[_popover presentPopoverFromRect:self.imageView.bounds inView:self.imageView permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
else {
[self presentModalViewController:imgPicker animated:YES];
}
[self.imgPicker resignFirstResponder];
}
// Sets the image in the UIImageView
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)img editingInfo:(NSDictionary *)editInfo {
if (imageView.image == nil) {
imageView.image = img;
[self.array addObject:imageView];
[picker dismissModalViewControllerAnimated:YES];
[self.popover dismissPopoverAnimated:YES];
return;
}
if (imageView2.image == nil) {
imageView2.image = img;
NSLog(#"The image is a %#", imageView);
[self.array addObject:imageView2];
[picker dismissModalViewControllerAnimated:YES];
[self.popover dismissPopoverAnimated:YES];
return;
}
if (imageView3.image == nil) {
imageView3.image = img;
[self.array addObject:imageView3];
[picker dismissModalViewControllerAnimated:YES];
[self.popover dismissPopoverAnimated:YES];
return;
}
if (imageView4.image == nil) {
imageView4.image = img;
[self.array addObject:imageView4];
[picker dismissModalViewControllerAnimated:YES];
[self.popover dismissPopoverAnimated:YES];
return;
}
if (imageView5.image == nil) {
imageView5.image = img;
[self.array addObject:imageView5];
[picker dismissModalViewControllerAnimated:YES];
[self.popover dismissPopoverAnimated:YES];
return;
}
}
UPDATE: Here is my current code:
- (IBAction)grabImage {
if (self.imgPicker == nil) {
self.imgPicker = [[UIImagePickerController alloc] init];
}
self.imgPicker.delegate = self;
self.imgPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
_popover = [[UIPopoverController alloc] initWithContentViewController:imgPicker];
[_popover presentPopoverFromRect:self.imageView.bounds inView:self.imageView permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
else {
[self presentModalViewController:imgPicker animated:YES];
}
[self.imgPicker resignFirstResponder];
}
From the other questions linked, it sounds like this is an Apple bug, but related to creating multiple UIImagePickerControllers. You're only presenting one image picker controller at a time, so maybe you should create one the first time you call your grabImage and then reuse it instead of creating a new one each time.

iOS: Image Will Not Delete From Array

I'm working on an app that behaves like a photo gallery, and I'm implementing the option to have the user delete photos from their gallery. To accomplish this, I decided to place an invisible button over each picture. When the user hits an "Edit" button, the hidden delete buttons over each picture become active. I'm using the same IBOutlet over each of the hidden buttons for simplicity, and I've tagged each button appropriately in Interface Builder. When the user taps the button over the picture, an alert view appears asking if they really want to delete it. If they click yes, I call removeObjectAtIndex. Here is the code I'm using:
- (IBAction)deleteButtonPressed:(id)sender {
NSLog(#"Sender is %#", sender);
UIAlertView *deleteAlertView = [[UIAlertView alloc] initWithTitle:#"Delete"
message:#"Are you sure you want to delete this photo?"
delegate:self
cancelButtonTitle:#"No"
otherButtonTitles:#"Yes", nil];
[deleteAlertView show];
int imageIndex = ((UIButton *)sender).tag;
deleteAlertView.tag = imageIndex;
}
- (void)alertView: (UIAlertView *) alertView
clickedButtonAtIndex: (NSInteger) buttonIndex
{
if (buttonIndex != [alertView cancelButtonIndex]) {
NSLog(#"User Clicked Yes.");
[self.array removeObjectAtIndex: alertView.tag];
}
[self.user setObject:array forKey:#"images"];
}
The issue here is that when I click "Yes" in the alert view, nothing happens. However, if I tap on the image and click "Yes" a second time, the app crashes, and the debug states:
Terminating app due to uncaught exception 'NSRangeException', reason: '-[__NSCFArray removeObjectAtIndex:]: index (0) beyond bounds (0)' So, I'm not sure where to go from here, I'm still very new to programming and everything looks correct to me. Any help is much appreciated, thanks!
Here is how I add them into the array:
////start of saving////
- (void)viewWillAppear:(BOOL)animated
{
self.user = [NSUserDefaults standardUserDefaults];
self.array = [[self.user objectForKey:#"images"]mutableCopy];
while(self.array == nil)
{
[self.user setObject:[NSMutableArray arrayWithObject:#""] forKey:#"images"];
self.array = [[self.user objectForKey:#"images"]mutableCopy];
NSLog(#"%#",#"attempting to create an array to store the images in");
}
}
- (void)applicationDidEnterBackground:(UIApplication*)application {
NSLog(#"Image on didenterbackground: %#", imageView);
self.array = [NSMutableArray arrayWithObject:[NSData dataWithData:UIImagePNGRepresentation(imageView.image)]];
[self.array addObject:[NSData dataWithData:UIImagePNGRepresentation(imageView2.image)]];
[self.array addObject:[NSData dataWithData:UIImagePNGRepresentation(imageView3.image)]];
[self.array addObject:[NSData dataWithData:UIImagePNGRepresentation(imageView4.image)]];
[self.array addObject:[NSData dataWithData:UIImagePNGRepresentation(imageView5.image)]];
[self.user setObject:self.array forKey:#"images"];
[user synchronize];
}
- (void)viewDidLoad
{
self.user = [NSUserDefaults standardUserDefaults];
NSLog(#"It is %#", self.user);
self.array = [[self.user objectForKey:#"images"]mutableCopy];
imageView.image = [[UIImage alloc] initWithData:[self.array objectAtIndex:0]];
imageView2.image = [[UIImage alloc] initWithData:[self.array objectAtIndex:1]];
imageView3.image = [[UIImage alloc] initWithData:[self.array objectAtIndex:2]];
imageView4.image = [[UIImage alloc] initWithData:[self.array objectAtIndex:3]];
imageView5.image = [[UIImage alloc] initWithData:[self.array objectAtIndex:4]];
imageView6.image = [[UIImage alloc] initWithData:[self.array objectAtIndex:5]];
UIApplication *app = [UIApplication sharedApplication];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(applicationDidEnterBackground:)
name:UIApplicationDidEnterBackgroundNotification
object:app];
backToGalleryButton.hidden = YES;
tapToDeleteLabel.hidden = YES;
deleteButton1.hidden = YES;
[super viewDidLoad];
}
- (void)viewDidUnload
{
self.user = nil;
}
////end of saving
///// shows the hidden and invisible "delete" button over each photo.
- (IBAction)editButtonPressed:(id)sender {
grabButton.hidden = YES;
editButton.hidden = YES;
backToGalleryButton.hidden = NO;
tapToDeleteLabel.hidden = NO;
deleteButton1.hidden = NO;
}
- (IBAction)deleteButtonPressed:(id)sender {
NSLog(#"Sender is %#", sender);
UIAlertView *deleteAlertView = [[UIAlertView alloc] initWithTitle:#"Delete"
message:#"Are you sure you want to delete this photo?"
delegate:self
cancelButtonTitle:#"No"
otherButtonTitles:#"Yes", nil];
[deleteAlertView show];
int imageIndex = ((UIButton *)sender).tag;
deleteAlertView.tag = imageIndex;
}
- (void)alertView: (UIAlertView *) alertView
clickedButtonAtIndex: (NSInteger) buttonIndex
{
if (buttonIndex != [alertView cancelButtonIndex]) {
NSLog(#"User Clicked Yes.");
NSLog(#"Array: %#, index: %d", self.array, alertView.tag);
[self.array removeObjectAtIndex: alertView.tag];
}
[self.user setObject:array forKey:#"images"];
}
#end
EDIT: This is the code I use to put the objects into the UIImageView from the users camera roll:
- (IBAction)grabImage {
self.imgPicker = [[UIImagePickerController alloc] init];
self.imgPicker.delegate = self;
self.imgPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
_popover = [[UIPopoverController alloc] initWithContentViewController:imgPicker];
[_popover presentPopoverFromRect:self.imageView.bounds inView:self.imageView permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
else {
[self presentModalViewController:imgPicker animated:YES];
}
[self.imgPicker resignFirstResponder];
}
// Sets the image in the UIImageView
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)img editingInfo:(NSDictionary *)editInfo {
if (imageView.image == nil) {
imageView.image = img;
[picker dismissModalViewControllerAnimated:YES];
[self.popover dismissPopoverAnimated:YES];
return;
}
if (imageView2.image == nil) {
imageView2.image = img;
[picker dismissModalViewControllerAnimated:YES];
[self.popover dismissPopoverAnimated:YES];
return;
}
if (imageView3.image == nil) {
imageView3.image = img;
[picker dismissModalViewControllerAnimated:YES];
[self.popover dismissPopoverAnimated:YES];
return;
}
if (imageView4.image == nil) {
imageView4.image = img;
[picker dismissModalViewControllerAnimated:YES];
[self.popover dismissPopoverAnimated:YES];
return;
}
}
When I added NSLog(#"Array: %#, index: %d", self.array, alertView.tag); just before removeAtIndex the console says 2012-04-03 18:39:39.066 AppName[1631:f803] Array: (null), index: 0. Could that be the cause? I'm not sure why it would be, I think the code looks fine.
Removing the image from the array is not the only step you have to take. Your code is correct for removing the image from the array, which is why you get image out of bounds the second time, but you also need to remove the image from the UI so the user can no longer delete an image that is not there.
There are many oddities with this code but I think the problem is that you are not calling super on your viewwillappear and viewdidload functions. I would get rid of your viewWillAppear method as it serves no purpose.

iOS: UIImagePickerController and ResignFirstResponder

I have an application that allows the user to select a photo from their camera roll, and display it in a UIImageView. But, after they tap on which image they would like to display, the camera roll's view does not disappear. So, I figured that I would need to simply call [sender resignFirstResponder];. But, this did not do the trick. I've been trying multiple things and doing searching around, but to no avail. I'm very new to Objective-C, so any help is much appreciated. Here is the code I'm working with:
(imgPicker is the UIImagePickerController.)
- (IBAction)grabImage(id)sender {
self.imgPicker = [[UIImagePickerController alloc] init];
self.imgPicker.delegate = self;
self.imgPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
_popover = [[UIPopoverController alloc] initWithContentViewController:imgPicker];
[_popover presentPopoverFromRect:self.imageView.bounds inView:self.imageView permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
else {
[self presentModalViewController:imgPicker animated:YES];
}
[self.imgPicker resignFirstResponder];
}
And this may or may not be relevant to the issue:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)img editingInfo:(NSDictionary *)editInfo {
if (imageView.image == nil) {
imageView.image = img;
[[picker parentViewController] dismissModalViewControllerAnimated:YES];
return;
}
if (imageView2.image == nil) {
imageView2.image = img;
[[picker parentViewController] dismissModalViewControllerAnimated:YES];
return;
}
}
You need just this line to dismiss modal picker in your delegate method:
[picker dismissModalViewControllerAnimated:YES];
resignFirstResponder in this case is useless
Try
[self dismissModalViewControllerAnimated:YES];
As you want to dismiss only picker view and not parent view of picker
you just have to use:
[picker dismissModalViewControllerAnimated:YES];
and you are done.