I use standard ABPeoplePickerNavigationController and when I had dragged table with contacts I saw that top bar is transparent. I can't solve it. It looks awful.
I tried to set [UIColor whiteColor] to everything I can reach: navigationBar, all subviews of ABPeoplePickerNavigationController and all subviews of it's topViewController. I tried to set different bar styles to navigation bar. Nothing help.
Here is code
#interface MNFindClientVC () <ABPeoplePickerNavigationControllerDelegate>
#property (nonatomic, strong) ABPeoplePickerNavigationController *addressBookController;
-(void)openPhoneBook;
#end
#implementation MNFindClientVC
-(void)viewDidLoad
{
[super viewDidLoad];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:#"phonebook"] style:UIBarButtonItemStyleBordered target:self action:#selector(openPhoneBook)];
self.addressBookController = [[ABPeoplePickerNavigationController alloc] init];
self.addressBookController.peoplePickerDelegate = self;
}
-(void)openPhoneBook
{
[self presentViewController:self.addressBookController animated:YES completion:nil];
}
#end
Sorry for my english. Thank you:)
I had the same problem when using a UINavigationBar that was translucent. You can solve this problem by disabling translucency of the UINavigationBar when in a ABPeoplePickerNavigationContrller with the following code (Tested in iOS 8):
_addressBookController = [[ABPeoplePickerNavigationController alloc] init];
[_addressBookController setPeoplePickerDelegate:self];
[[UINavigationBar appearanceWhenContainedIn:[ABPeoplePickerNavigationController class], nil] setTranslucent:NO];
[self presentViewController:_addressBookController animated:YES completion:nil];
Related
Have tried [[self jotNotes] resignFirstResponder]; , have tried [self endEditing:YES];
So I have my NoteViewController, which inherits UIViewController, and tries to implement the delegate like so
#interface NOTEController : UIViewController <UITextViewDelegate>
#end
#implementation NOTEController
-(id)init {
self = [super init];
if (self) {
// self.delegate = self; //doesnt let me set this, so i assume i do not do that here
NOTEControllerView * mainView = [[NOTEControllerView alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.view = mainView; //just a plain custom uiview subclass its boring and not special
}
return self;
}
#end
and then in the mainView, i have a bunch of sub-views that are basically a square with a UITextView inside.
the squares class is like this, and they're the ones im trying to dismiss the keyboard from, heres where i set the delegate, the dismissKB method, and the UITextView code. Currently, it will log my keyboard method when pressing the done button, but the keyboard is still present. Would really appreciate if anyone could help me understand why
#interface NOTESubview : UIView <UITextFieldDelegate>
#property (nonatomic, weak) id<UITextFieldDelegate> delegate;
-(UITextView *)jotNotes;
#end
#implementation NOTESubview
-(id)initWithFrame:(CGRect)arg1 {
self = [super initWithFrame:arg1];
if (self) {
self.delegate = self;
[self addSubview:[self jotNotes]];
}
return self;
}
-(UITextView *)jotNotes {
UITextView * jotNotes = [[UITextView alloc] initWithFrame:CGRectMake(0, self.frame.size.height/5.7, self.frame.size.width, self.frame.size.height - self.frame.size.height/5.7)];
UIToolbar* keyboardTextViewBar = [[UIToolbar alloc] init];
keyboardTextViewBar.barStyle = UIBarStyleDefault;
[keyboardTextViewBar sizeToFit];
UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
UIBarButtonItem* doneButton = [[UIBarButtonItem alloc] initWithTitle:#"Done"
style:UIBarButtonItemStylePlain target:self
action:#selector(dismissKB:)];
[keyboardTextViewBar setItems:[NSArray arrayWithObjects:flexSpace, doneButton, nil]];
jotNotes.inputAccessoryView = keyboardTextViewBar;
jotNotes.delegate = self.delegate;
return jotNotes;
}
-(void)dismissKB:(UIBarButtonItem *)sender {
//this will log, so im not sure why it wont resign the board no matter what i try
NSLog(#"keyboard attempted to dismiss by %#", sender);
[[self jotNotes] resignFirstResponder];
}
I suspect that when the dismissKB method is called, its actually not the one who is currently the first responder.
However, there's a trick where you can just "dismiss the keyboard" from anywhere in your app. You might wanna give it a try:
[[[[UIApplication sharedApplication] delegate] window] endEditing:YES];
Add the following line where you are trying to dismiss the keyboard:
[self endEditing:YES];
My app is a tab bar app with many navigation controllers.
I want these navigation controllers to handle login/logout actions with a custom right bar button. So I've set up my tab bar in AppDelegate this way :
MyFirstViewController *firstViewController = [[MyFirstViewController alloc] init];
UIViewController *firstNavigationController = [[CustomNavigationController alloc]
initWithRootViewController:firstViewController];
MySecondViewController *secondViewController = [[MySecondViewController alloc] init];
UIViewController *secondNavigationController = [[CustomNavigationController alloc]
secondViewController]
initWithRootViewController:secondViewController];
....
[tabBarController setViewControllers:#[firstNavigationController, secondNavigationController]];
Then CustomNavigationController :
#implementation ConnectionNavigationController
- (void) viewDidLoad
{
[self displayConnectionButton];
}
- (void) displayConnectionButton
{
UIImage *portraitImage, *landscapeImage;
portraitImage = [UIImage imageNamed:#"conn.png"];
landscapeImage = [UIImage imageNamed:#"connLandscape.png"];
UIBarButtonItem *connButton = [[UIBarButtonItem alloc]
initWithImage:[portraitImage
imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]
landscapeImagePhone:[landscapeImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]
style:UIBarButtonItemStylePlain target:self action:#selector(showConnectionPopup)];
self.navigationItem.rightBarButtonItem = connButton;
}
#end
I tried with viewDidLoad, viewDidAppear, viewWillAppear but nothing works, I can't get this button to show in the navigation bar. I also tried to add reloadInputViews or setNeedsDisplay. What should I do?
Thanks for your help
Edit : interface of CustomNavigationController
#interface ConnectionNavigationController : UINavigationController
- (void) displayConnectionButton;
#end
From what I understand you should add the displayConnectionButton method to the relevant UIViewController subclass and not to your UINavigationController subclass as this only contains the stack of view controllers.
E.g.
#implementation MyFirstViewController
- (void) viewDidLoad
{
[self displayConnectionButton];
}
- (void) displayConnectionButton
{
UIImage *portraitImage, *landscapeImage;
portraitImage = [UIImage imageNamed:#"conn.png"];
landscapeImage = [UIImage imageNamed:#"connLandscape.png"];
UIBarButtonItem *connButton = [[UIBarButtonItem alloc]
initWithImage:[portraitImage
imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]
landscapeImagePhone:[landscapeImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]
style:UIBarButtonItemStylePlain target:self action:#selector(showConnectionPopup)];
self.navigationItem.rightBarButtonItem = connButton;
}
#end
As a note if you put a breakpoint on your displayConnectionButton in your CustomNavigationController and po self.viewControllers I think you will get an empty array (i.e. no view controllers)
I have replaced the nave bar in my iOS7 app in Xcode 5 using the following code (also removed the status bar if that matters):
AppDelegate.M
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:#"navBar"] forBarMetrics:UIBarMetricsDefault];
In one of my image view controllers I am using a UIImagePicker to pick a profile pic. The problem is when it goes to the photo gallery it uses the main "navBar" image which hides some controls and basically stacks 2 of the same nav bars on top. Can I have a different nav bar for the photogallery? Here is the View controllers:
FirstView.H
#import <UIKit/UIKit.h>
#interface IBFirstViewController : UIViewController <UIImagePickerControllerDelegate, UINavigationControllerDelegate>
#property (weak, nonatomic) IBOutlet UILabel *userName;
#property (weak, nonatomic) IBOutlet UILabel *userEmail;
#property (weak, nonatomic) IBOutlet UIImageView *backgroundImage;
- (IBAction)logout:(id)sender;
- (IBAction)edit:(id)sender;
#end
FirstView.M
- (IBAction)edit:(id)sender {
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc]init];
imagePickerController.modalPresentationStyle = UIModalPresentationCurrentContext;
imagePickerController.delegate = self;
[self presentViewController:imagePickerController animated:NO completion:Nil];
}
I have similar problem when using [UINavigationBar appearance] to custom navigation bar on iOS7. If we do that, all iOS native controller which is subclass of UINavigationController, is effected too, ex: UIImagePickerController, MFMessageComposeViewController...
If you want to use custom navigation style within your controllers, you have to apply with your UINavigationController instance instead of using [UINavigationBar appearance] singleton.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
...
UINavigationController *navigationController = (UINavigationController*)self.window.rootViewController;
[navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:#"navBar"] forBarMetrics:UIBarMetricsDefault];
...
}
Or in my case, I create subclass of UINavigationController
- (void)viewDidLoad
{
[super viewDidLoad];
[self setupAppearance];
...
}
- (void)setupAppearance
{
[self.navigationBar setBackgroundImage:[UIImage imageNamed:#"navBar"]
}
Then, when you create UIImagePickerController instance, just custom its navigation bar
- (IBAction)edit:(id)sender {
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc]init];
imagePickerController.modalPresentationStyle = UIModalPresentationCurrentContext;
imagePickerController.delegate = self;
// Custom another navigation style
[imagePickerController.navigationBar setBackgroundImage:[UIImage imageNamed:#"NEW-NAV-BAR-IMAGE"];
[self presentViewController:imagePickerController animated:NO completion:Nil];
}
I have two buttons on my navbar. One on the left and one on the right. The button on the left works but the one on the right does not work. If I swap the buttons, recompile and load the issue persist with the right button regardless of which button is in the right spot of the bar.
Also while the left button works as soon as I try to use the right button the left button stops working too.
How do I make the right button work? Below is the code.
UINavigationBar *NavBar = [[UINavigationBar alloc] init];
[NavBar sizeToFit];
[self.view addSubview:NavBar];
UIBarButtonItem *cmdBack = [[UIBarButtonItem alloc] initWithTitle:#"Back"
style:UIBarButtonItemStyleBordered
target:self
action:#selector(cmdBackClicked:)];
UIBarButtonItem *cmdAddDevice = [[UIBarButtonItem alloc] initWithTitle:#"Add Device"
style:UIBarButtonItemStyleBordered
target:self
action:#selector(cmdAddDeviceClicked:)];
UINavigationItem *NavBarItems = [[UINavigationItem alloc] initWithTitle:#"Settings"];
NavBarItems.leftBarButtonItem = cmdBack;
NavBarItems.rightBarButtonItem = cmdAddDevice;
NavBar.items = [NSArray arrayWithObjects:NavBarItems, nil];
The functions for the buttons are these
- (void) cmdBackClicked:(id)sender
{
[self.view removeFromSuperview];
}
- (void) cmdAddDeviceClicked:(id)sender
{
vcAddDevice *ViewAddDevice = [[vcAddDevice alloc] initWithNibName:#"vcAddDevice" bundle:nil];
[ViewAddDevice SetEditDeviceMode:[NSString stringWithFormat:#"No"]];
[self.view addSubview:ViewAddDevice.view];
}
In the .h file I have this.
#import <UIKit/UIKit.h>
#import "vcAddDevice.h"
#interface ViewControllerSettings : UIViewController<vcAddDeviceControllerDelegate, UITableViewDelegate, UITableViewDataSource>
- (IBAction) cmdBackClicked:(id) sender;
- (IBAction) cmdAddDeviceClicked:(id) sender;
#end
I am trying to create UIViewController programmatically for ModalView presentation on the main window of the application and in this UIViewController on top i have is Navigation bar with done button to dismiss the view and below the navigation bar it has UITextView.
So my question is that the UITextview which i want to create below the navigation bar will come in the ViewdidLoad Method or i m doing right to show separate medthod to setup textview .
In the Infoviewcontroller.h file have following code:
#import <UIKit/UIKit.h>
#interface Infoviewcontroller : UIViewController <UITextViewDelegate>{
UITextView *textView;
}
#property (nonatomic, retain) UITextView *textView;
#property (nonatomic, assign) UINavigationBar *navBar;
#end
Then in the infoviewcontroller.m file have the following code:
#import "Infoviewcontroller.h"
#implementation Infoviewcontroller
#synthesize textView;
#synthesize navBar;
-(void)dealloc{
[textView release];
[navBar release];
[super dealloc];
}
-(void)setupTextView {
self.textView = [[[UITextView alloc] initWithFrame:self.view.frame] autorelease];
self.textView.textColor = [UIColor redColor];
self.textView.font = [UIFont fontWithName:#"System Bold" size:13];
self.textView.delegate = self;
self.textView.backgroundColor = [UIColor whiteColor];
self.textView.textAlignment = UITextAlignmentCenter;
self.textView.text = #"This is UITextView\nThis is UITextView\nThis is UITextView\nThis is UITextView";
[self.view addSubview: self.textView];
}
- (void)viewDidLoad {
[super viewDidLoad];
navBar = [[UINavigationBar alloc] init];
UINavigationItem *navItem = [[[UINavigationItem alloc] initWithTitle:#"ModalViewControllerTest"] autorelease];
UIBarButtonItem *done = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:#selector(dismissView:)] autorelease];
navItem.rightBarButtonItem = done;
navBar.items = [NSArray arrayWithObject:navItem];
[self.view addSubview:navBar];
}
Regarding creation of UINavigationBar programmatically, I found following blog post helpful http://cps.liridesce.com/?p=100. Example overrides loadView rather than viewDidLoad method, but I think in your case using viewDidLoad should have the same effect.
I would also add viewDidUnload where I would set to nil navBar and textView properties.
I'm not quite sure why you need separate setupTextView method, unless you are calling it from different places of your UIViewController. I would just keep everything together in viewDidUnload.