navigationItem.prompt & UIImagePickerController - iphone

Is it possible to make calls to navigationItem on a UIImagePickerController? Specifically, the image picker? Below I've linked an image of what I'm trying to achieve ( screen shot taken from another app doing the same thing). Once the user selects an image from the picker the navigationItem.prompt is set and, though I think it might be a HIG violation, the right bar button is changed from the standard cancel button. I can set the prompt on a "normal" view no problem with:
self.navigationItem.prompt = myString;
But this does not seem to work when I try to use it in the context of a picker with:
myPicker.navigationItem.prompt = myString;
I've tried using it when the picker is created and also in didFinishPickingMediaWithInfo: which is really where I need to set it as I'm letting the user select multiple images instead of dismissing the picker as soon as one image is selected. Nothing seems to work.
Here's a image of the desired behavior:
http://i51.photobucket.com/albums/f353/zoso5th/after.png

Someone answered this for me on the Apple dev forums:
UINavigationBar *bar = picker.navigationBar;
UINavigationItem *navItem = bar.topItem;
navItem.prompt = #"Some new prompt";
I wasn't correctly accessing the navbar.

Someone answered this for me on the Apple dev forums:
UINavigationBar *bar = picker.navigationBar;
UINavigationItem *navItem = bar.topItem;
navItem.prompt = #"Some new prompt";
I wasn't correctly accessing the navbar.
Use the code after calling 'presentModalViewController'.....like below...
[controller presentModalViewController:imagePickerController animated:YES];
UINavigationBar *bar = picker.navigationBar;
UINavigationItem *navItem = bar.topItem;
navItem.prompt = #"Some new prompt";

Related

UIButton buttonWithType:101, Will they reject my app?

Greetings,
In one of my projects I wanted to create back type button(with pointer) in the navigation bar, I googled around and found that using the following code, it can be achieved.
UIButton *someButton = [UIButton buttonWithType:101];
UIBarButtonItem *someBarButton = [[UIBarButtonItem alloc] initWithCustomView:someButton];
I want to upload this app on Apple's app store.
Is there any chance that this will get my app rejected, since buttonWithType:101 is not documented any where?
Also i m not using this bar button item in its generic way, i.e. it wont pop the view controller.
Please guide.
Regards,
I propose that you generate Image for your need, just by running this code and delete it after you generate the image:
- (void)viewDidLoad {
...
someButton = [UIButton buttonWithType:101];
UIBarButtonItem *someBarButton = [[UIBarButtonItem alloc] initWithCustomView:someButton];
self.navigationItem.leftBarButtonItem = someBarButton;
...
}
and
- (void)viewWillAppear:(BOOL)animated {
....
UIImage *img1 = [someButton backgroundImageForState:UIControlStateNormal];
NSData *newData = UIImagePNGRepresentation(img1);
NSFileManager *fileManager =[NSFileManager defaultManager];
BOOL filecreationSuccess = [fileManager createFileAtPath:#"/Users/macbookmac/Desktop/tester.png" contents:newData attributes:nil];
...
}
most probably yes.. in some cases, few things do slip under the radar, but why take chances..
if you are doing this for your client/company, would you risk having a rejection from app store on your hands..
its safer to create a pointed button image and use it with custom button...
If you are trying to control what text appears in the Navigation controller's back button, you can do that with the UIViewController's UINavigationItem. It can contain both the title for the current view and the text to use for the next view's "back" button. This can be set in XIB as well.

Reload / Refresh tab bar items in a ViewController ?

I am trying to change images of my tabbar in a ViewController, but to display the new images, I must click on each tab bar item.
for (CustomTabBarItem *myItem in self.tabBarController.tabBar.items){
myItem.enabled = YES;
myItem.badgeValue = #"1";
UIImage *myImage = [[UIImage alloc] initWithContentsOfFile:[[DesignManager sharedManager] getPathOfFile:#"test.png"]];
*myItem.imageSelect= *myImage; // change images of each item. don't appear if I dont click on the item
}
Anyone know How can I can display directly these images?
Thanks
You need to replace the old tab bar item with a new one. You can't update the image dynamically otherwise.
The easiest way to do this is to set the tabBarItem property of the view-controller represented by a given tab. If you wanted to do this from within that view controller, just write:
self.tabBarItem = [[UITabBarItem alloc] initWithTitle: #"title" image: myImage: tag: nil];
Or, you could do this from somewhere else, say your app delegate:
UIViewController* vc = [tabBarController.viewControllers objectAtIndex: 3];
vc.tabBarItem = [[UITabBarItem alloc] initWithTitle: #"title" image: myImage: tag: nil];
I know this is an old question. I ran into the same problem when I need to update the badge value from another active tab. Creating another UITabBarItem will solve your current problem but causes potential memory leak when this code is called many times. Plus, when other view controllers access the tab, they do not have reference to newly created UITabBarItem. My trick is
vc.tabBarItem = vc.tabBarItem;
It works for me.

How can I disable re-taking of pictures?

I use the built-in camera of the Iphone in my apps dans I have two questions.
UIImagePickerController *ipc = [[UIImagePickerController alloc] init];
ipc.sourceType = UIImagePickerControllerSourceTypeCamera;
ipc.delegate = self;
ipc.allowsEditing = NO;
[self presentModalViewController:ipc animated:YES];
First, my camera let the user use the picture he took or Retake, I want to take off this option, the user must have only one chance to take his picture.
Second, I want a change the title of the Cancel button on the left, because my app is in french.
For the "Cancel" button, I think you may try with internalization and localization. I don't know exactly how to do.
If you want to control the camera flow, it is harder than the normal way. You have to replace the default control buttons (in the bottom of the camera screen) with your own control. There are 2 methods that you need to do:
First, you need to set showCameraControls to NO: picker.showCameraControls = NO
#property(nonatomic) BOOL showsCameraControls
Then you need to supply your own view: picker.cameraOverlayView = YOUR_OWN_VIEW
#property(nonatomic, retain) UIView *cameraOverlayView

How to set title in the MFMailComposerViewController?

I am trying to set the title of MFMailComposerViewController , which is a subclass of UINavigationController.
I am using these following ways :
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
[picker.navigationController navigationItem].title = #"Send Mail";
[[picker navigationItem] setTitle:#"Send Mail"];
But I am not able to set the Title.
Am i doing it wrong ??
Is there any other method to do so ??
Thanks
The title is updated whenever the subject changes. You cannot change the title programmatically within AppStore restrictions. You may use -setSubject: to initialize the subject.
(A bad way to solve this is to create a very high-level window with a label that covers original title. This is very difficult to make this work with orientation change.)

Force scope bar below UISearchBar

I have a UISearchBar and UISearchDisplayController, everything works great but my scope selector displays beside the text field instead of below it. I know that this is the expected action when the device is in landscape, but since I have the UISearchBar in the master view of a UISplitViewController it ends up looking like this:
Is there any way to force the scope bar to display below the text field in all interface orientations (I know that this works nicely in Mail.app on the iPad, so its possibly, but who knows if Apple decided to hide the option to do so)
This is not part of the public API. Hopefully it will be added in the future. It can be accomplished using Private APIs, looking through a UIKit class dump will help you there.
Good luck!
edit: Note that using private APIs can get you rejected from the app store, as most people already know.
I used the UISearchDisplayDelegate to show and hide the scope bar.
-(void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller
{
[controller.searchBar setShowsScopeBar:YES];
}
-(void)searchDisplayControllerWillEndSearch:(UISearchDisplayController *)controller
{
[controller.searchBar setShowsScopeBar:NO];
}
Don't use private APIs. Instead, follow Apple's recommendation from IOS User Interface Guidelines:
When a search bar is present, a scope bar can appear near it. The
scope bar displays below the search bar, regardless of orientation,
unless you use a search display controller in your code (for more
information on the way this works, see UISearchDisplayController Class
Reference). When you use a search display controller, the scope bar is
displayed within the search bar to the right of the search field when
the device is in landscape orientation (in portrait orientation, it’s
below the search bar).
This worked for me using storyboards.
Why not just set up your search bar programattically? Here's what I'm using on my current project. It hides the search bar until the user scrolls up, and the scope bar is loaded below the text field when they start typing items. From there just filter as usual:
- (void)setupSearchBar {
self.searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 44)];
self.searchBar.showsScopeBar = YES;
self.searchBar.scopeButtonTitles = [NSArray arrayWithObjects:#"Users", #"Groups", nil];
self.tableView.tableHeaderView = self.searchBar;
CGPoint offset = CGPointMake(0, self.searchBar.frame.size.height);
self.tableView.contentOffset = offset;
self.searchController = [[UISearchDisplayController alloc] initWithSearchBar:self.searchBar
contentsController:self];
self.searchController.searchResultsDataSource = self;
self.searchController.searchResultsDelegate = self;
self.searchController.delegate = self;
}
call [self setupSearchBar]; in viewDidLoad you're off to the races.