Set UIBarStyle of UIImagePickerController - iphone

I would like to set the bar style of a UIImagePickerController as following, but the bar is still UIBarStyleBlackTranslucent. Is it possible to set the bar style of UIImagePickerController? Thanks in advance!
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.navigationBar.barStyle = UIBarStyleBlack;
Edit 1
I can set the tint color through:
imagePicker.navigationBar.tintColor = UIColorFromRGB(0xCC6600);

Here's what worked for me (you need to test the class of the navigationController, not the viewController being presented, and you need to set a non-transparent background color as well it seems)
- (void)navigationController:(UINavigationController *)navigationController
willShowViewController:(UIViewController *)viewController
animated:(BOOL)animated
{
if ([navigationController isKindOfClass:[UIImagePickerController class]])
{
navigationController.navigationBar.barStyle = UIBarStyleBlack;
navigationController.navigationBar.backgroundColor = [UIColor blackColor];
}
}

imagePicker.navigationBar.tintColor=[UIColor blackColor];

You can make the change by implementing the UINavigationControllerDelegate method navigationController:willShowViewController:, like this:
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController
animated:(BOOL)animated {
if([viewController isKindOfClass:[UIImagePickerController class]])
navigationController.navigationBar.barStyle = UIBarStyleBlack;
}

Related

image picker not dismissing when picture tapped

when the bar button item is tapped the popover view shows fine but it does not dismiss when a photo is selected. Am I missing something? What should i do?
-(IBAction)addPhoto:(UIBarButtonItem *)sender
{
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
popover = [[UIPopoverController alloc] initWithContentViewController:imagePicker];
[popover presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)selectedImage editingInfo:(NSDictionary *)editingInfo
{
// Delete any existing image.
NSManagedObject *oldImage = imageClass.image;
if (oldImage != nil)
{
[imageClass.managedObjectContext deleteObject:oldImage];
}
// Create an image object for the new image.
NSManagedObject *myImage = [NSEntityDescription insertNewObjectForEntityForName:#"Image" inManagedObjectContext:imageClass.managedObjectContext];
imageClass.image = myImage;
// Set the image for the image managed object.
[image setValue:selectedImage forKey:#"image"];
[popover dismissPopoverAnimated:YES];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[[picker parentViewController] dismissViewControllerAnimated:YES completion:nil];
}
The issue is that you are trying to dismiss the image picker controller but you need to dismiss the popover that it is in. Things need to be dismissed based on how they were presented.
Change:
[self dismissViewControllerAnimated:YES completion:nil];
to:
[popover dismissPopoverAnimated:YES];
Calling dismissViewControllerAnimated:completion: would be used if you have called presentViewController:animated:completion:.
To dismiss UIPopoverViewController on the selection of a photo from gallery, you need to add following lines in didFinishPickingMediaWithInfo method after picking an image.
- (void)imagePickerController:(UIImagePickerController *)imagePicker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[popover dismissPopoverAnimated:YES];
[imagePicker dismissModalViewControllerAnimated:YES];
}
You've not set delegate of imagePicker to self. Plus you need to take popover as instance variable to dismiss in delegate method.
1) in you .h you must add <UIImagePickerControllerDelegate>
2) add imagePicker.delegate=self; so your addPhoto method should look as below:
-(IBAction)addPhoto:(UIBarButtonItem *)sender {
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate=self; //add this line to your code
popover = [[UIPopoverController alloc]
initWithContentViewController:imagePicker];
[popover presentPopoverFromBarButtonItem:sender
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
}
just give the delegate UIPopoverControllerDelegate and UIImagePickerControllerDelegate in .h file
you must add UIImagePickerControllerDelegate to your corresponding .h file and also Check this Code
-(IBAction)addPhoto:(UIBarButtonItem *)sender
{
UIImagePickerController *imagePicker3 = [[UIImagePickerController alloc] init];
imagePicker3.delegate = self;
imagePicker3.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker3.allowsEditing = YES;
imagePicker3.mediaTypes = [NSArray arrayWithObject:#"public.image"]
[self presentModalViewController:imagePicker3 animated:YES];
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[self dismissModalViewControllerAnimated:YES];
_imageselected.image=[info valueForKey:UIImagePickerControllerEditedImage];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[self dismissModalViewControllerAnimated:YES];
}
In case someone is still experiencing this infamous error when using UIImagePickerController:
Assigning to 'id <UINavigationControllerDelegate,UIImagePickerControllerDelegate>' from incompatible type 'DetailViewController *const __strong'
try to move
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
to the
- (void)viewDidLoad{
//do your stuff
}
and don't forget to include the delegate protocol definitions (<UINavigationControllerDelegate,UIImagePickerControllerDelegate>) in the corresponding .h file.
This solved my problem, hope it's gonna help someone else. Don't know if its the best solution, but worked for me in a similar case.

I want to add transition effect with every image of the slide show which i created so how i will add?

Here is few code related to my slide show,What i want is to add transition effect on each img.Img will be picked from library and add the transition effect on that img so when we play the slide the image with specific transition should be played means when 1 transition will disapear with their trans. effect another will appear with their transition effect..
- (void)addPhoto
{
if (imagePicker == nil)
{
imagePicker = [[UIImagePickerController alloc] init];
imagePicker.allowsImageEditing = YES;
imagePicker.sourceType =
UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.delegate = self;
}
returnFromImagePicker = YES;
[self presentModalViewController:imagePicker animated:YES];
}
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingImage:(UIImage *)img editingInfo:
(NSDictionary *)editInfo
{
[pictures addObject:img];
UITableView *table = (UITableView *)self.view;
[table insertRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath
indexPathForRow:pictures.count - 1 inSection:0]] withRowAnimation:
UITableViewRowAnimationRight];
[self dismissModalViewControllerAnimated:YES];
}
- (void)addEffect
{
if (effectSheet == nil)
{
effectSheet = [[UIActionSheet alloc] initWithTitle:#"Choose Effect"
delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil
otherButtonTitles:#"Fade", #"Slide In", nil];
}
[effectSheet showInView:self.view];
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:
(NSInteger)buttonIndex
{
effect = buttonIndex;
}
UIView has a class method by which you can transition from one view to another with a transition. Use it like this:
[UIView transitionFromView:currentView toView:newView duration:1.0 options:UIViewAnimationOptionTransitionFlipFromLeft completion:nil];
For more information refer to Apple's UIView documentation.

problem with "title" in UINavigationController

I am having a problem with title and UINavigationController. I am using the following code at UIViewControllerCurrent and when I get back from NextViewController, the title of the NavBar is still "Previous" ..Can anyone kindly help me out with this problem ? Thanks.
[self setTitle:#"Previous"];
NextViewController *controller = [[NextViewController alloc] init];
[[self navigationController] pushViewController:controller animated:YES];
[controller release], controller = nil;
- (void)viewWillAppear:(BOOL)animated; {
[self setTitle:#"Real Title"];
[super viewWillAppear:animated]; }
I would try to exchange the two lines
[self setTitle:#"Real Title"];
[super viewWillAppear:animated];
so that you get
[super viewDidAppear:animated];
[self setTitle:#"Real Title"];
and I would put these into viewDidAppear.
Try using UINavigationController delegate methods below.
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated;
- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated;
Use one of the delegate method to change title.
If dasdoms solution is not working the try the following.
In the NextViewController just before poping out run this code.
for (int i =0; i < [[self.navigationController viewControllers] count]; i++)
{
UIViewController *aController = [[self.navigationController viewControllers] objectAtIndex:i];
if ([aController isKindOfClass:[PreviousViewController class]])
{
PreviousViewController *aPreviousViewController = (PreviousViewController *)aController;
aPreviousViewController.title = #" Real Title";
}
}

returning null inside tableview delegate

HI
I am working on UITablview based project. i like to load a new view when ever a cell got click. i am using following code in didselectRowAtIndexPath delegate method.
The below coding is not showing any error but new view not get load and [self navigationController] is returning null.
inside Viewdidload function [self navigationcontroller] returning proper value. but inside Delegate method [self navigationcontroller] returns null.
/// inside appDelegate class
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.viewController = [[LAMainViewController_iPhone alloc]initWithNibName:#"LAMainViewController_iPhone" bundle:nil];
UINavigationController *controller = [[UINavigationController alloc]initWithRootViewController:viewController];
[window addSubview:controller.view];
[controller release];
[window makeKeyAndVisible];
return YES;
}
/// inside LAmainviewcontroller.m
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
// Custom initialization
}
//self.navigationController.navigationBar.backgroundColor =[UIColor clearColor];// .title=#"test";
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
NSString *materialPlistPath = [[NSBundle mainBundle]pathForResource:#"materials" ofType:#"plist"];
materialList = [[NSArray alloc]initWithContentsOfFile:materialPlistPath];
materialTable.backgroundColor = [UIColor blackColor];
NSLog(#" dud kiad navigationController %#", self.navigationController);
//2010-10-20 15:22:03.809 LabAssistant[17368:207] dud kiad navigationController <UINavigationController: 0x5f3b160>
}
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:YES];
self.navigationController.navigationBarHidden = YES;
NSIndexPath *indexPath = [materialTable indexPathForSelectedRow];
[materialTable deselectRowAtIndexPath:indexPath animated:YES];
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
LAMaterialPropertiesViewController_iPhone *materialPropertyListView = [[[LAMaterialPropertiesViewController_iPhone alloc] initWithNibName:#"LAMaterialPropertiesViewController_iPhone" bundle:nil] autorelease];
materialPropertyListView.chemicalName = [[materialList objectAtIndex:[indexPath row]] objectForKey:#"materialProperty"];
[[self navigationController] pushViewController:materialPropertyListView animated:YES];
NSLog(#"%#",[self navigationController]);
///2010-10-20 16:20:42.634 LabAssistant[17656:207] navigationController (null)
}
please help me to fix this issue.
thanks!
Remove the autorelease from the init statement. Actually the viewcontroller is getting released before it gets pushed.
instead of
LAMaterialPropertiesViewController_iPhone *materialPropertyListView = [[[LAMaterialPropertiesViewController_iPhone alloc] initWithNibName:#"LAMaterialPropertiesViewController_iPhone" bundle:nil] autorelease];
try this
LAMaterialPropertiesViewController_iPhone *materialPropertyListView = [[LAMaterialPropertiesViewController_iPhone alloc] initWithNibName:#"LAMaterialPropertiesViewController_iPhone" bundle:nil];
Hope this will solve your problem.
I think the table view delegate is called before the navigation controller is set to the view controller.
Can you try reloading the tableview [tableview reloadData]; in viewWillAppear or viewDidAppear?

Using UIImagePickerController with UINavigationController

So I have a UINavigationController that pushes a UITableViewController from the rootViewController. From the UITableViewController, I want a UIImagePickerController to be pushed when I click a certain cell. How would I get the navigation controller to display the image picker?
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
[self presentModalViewController:imagePicker animated:YES];
// don't release imagePicker here
}
Then define UIPickerControllerDelegate in your tableViewController implementation.