Navigation bar doesn't appear using show (push) segue in iOS7.1 - ios

I have three devices with three iOS version. I hide the navigation bar in RootViewController. Then for each ViewController, I display the navigation bar as
- (void)viewDidLoad {
[super viewDidLoad];
self.view.userInteractionEnabled = YES;
// Do any additional setup after loading the view.
[self.navigationController setNavigationBarHidden:NO];
CGRect frame = CGRectMake(0, 0, 0, 44);
UILabel *label = [[UILabel alloc] initWithFrame:frame];
label.backgroundColor = [UIColor clearColor];
label.font = [UIFont fontWithName:#"Helvetica-Bold" size:20.0];
label.textAlignment = NSTextAlignmentCenter;
label.textColor = [UIColor blackColor];
label.text = #"Update Height";
self.navigationItem.titleView = label;
}
It works on two devices with iOS8.4 and iOS9.1, but not for iOS7.1. For the iOS7.1 device, if I change the segue to custom type, the navigation bar is displayed. But if I change to Show (Push) segue, the navigation bar doesn't show up.
What could be the problem?
I used segue from UIStoryBoard.
Thanks

read this link and then try this
//hide on current view controller
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:YES animated:YES];
}
// show on next view controller
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[self.navigationController setNavigationBarHidden:NO animated:YES];
}

Related

How to add and remove searchBar from navigationItem

I am having trouble adding and removing a UISearchControllers searchBar to a UINavigationBar.
Here is what I am doing:
Add the searchBar to the view
searchController = [[UISearchController alloc]initWithSearchResultsController:nil];
searchController.searchResultsUpdater = self;
searchController.searchBar.delegate = self;
searchController.dimsBackgroundDuringPresentation = NO;
searchController.hidesNavigationBarDuringPresentation = NO;
searchController.searchBar.searchBarStyle = UISearchBarStyleProminent;
searchController.searchBar.barTintColor = [UIColor blackColor];
searchController.searchBar.tintColor = [UIColor darkGrayColor];
[searchController.searchBar setFrame:CGRectMake(0, 200, 320, searchController.searchBar.frame.size.height)];
[self.view addSubview:searchController.searchBar];
On button click add the searchBar to the navigationItem
This works as expected
[self.navigationController setNavigationBarHidden:false];
self.navigationItem.titleView = searchController.searchBar;
self.navigationItem.hidesBackButton = true;
And here is where I am getting the strange behaviour:
On another button click remove the searchBar from the nav bar and add it back to the view
[searchController.searchBar removeFromSuperview];
[self.navigationController setNavigationBarHidden:YES animated:true];
[self.view addSubview:searchController.searchBar];
[searchController.searchBar setFrame:CGRectMake(0, 200, 320, searchController.searchBar.frame.size.height)];
The searchBar is removed from the Nav Bar as expected, but it is not returned to the main view. ( well i can't see it anywhere)
I log the value of the search bar I can see that it has the frame that I have given it.
Any help here would be greatly appreciated,
Thanks
You should set navigationItem .titleView to nil first and setFrame: in main thread.
- (IBAction)addBar:(id)sender {
self.navigationItem.titleView = nil;
[searchController.searchBar removeFromSuperview];
[self.navigationController setNavigationBarHidden:NO animated:YES];
self.navigationItem.titleView = searchController.searchBar;
self.navigationItem.hidesBackButton = YES;
}
- (IBAction)removeBar:(id)sender {
self.navigationItem.titleView = nil;
[searchController.searchBar removeFromSuperview];
[self.view addSubview:searchController.searchBar];
[self.navigationController setNavigationBarHidden:YES animated:YES];
dispatch_async(dispatch_get_main_queue(), ^{
[self->searchController.searchBar setFrame:CGRectMake(0, 200, 320, self->searchController.searchBar.frame.size.height)];
});
}
By the way, I think it is better that put the search bar in a wrapper UIView when adding to the navigationItem.titleView.

How to switch between tabs and directly show pushed view controller?

This is my code:
VideoDetailViewController *VideoDetailVC = [self.storyboard instantiateViewControllerWithIdentifier:#"VideoDetailViewController"];
UINavigationController * navigationController = (UINavigationController *) [[self tabBarController] selectedViewController];
[self.tabBarController setSelectedIndex:0];
[navigationController pushViewController:VideoDetailVC animated:YES];
I am writing this code in tabbar's second index. I want to directly go to the Video Detail screen, which is child view controller of tabbar's zero index. Everything works fine but what I see is: it shows a parent view controller which is tabbar's zero index. After a second it pushes to the Video Detail screen. I just don't want to show the zero index. What is the solution? Help will be appreciated.
EDITED:
#import "TWPhotoCollectionViewCell.h"
#implementation TWPhotoCollectionViewCell
- (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
self.imageView = [[UIImageView alloc] initWithFrame:self.bounds];
self.imageView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.imageView.layer.borderColor = [UIColor blueColor].CGColor;
[self.contentView addSubview:self.imageView];
}
return self;
}
- (void)setSelected:(BOOL)selected {
[super setSelected:selected];
self.imageView.layer.borderWidth = selected ? 2 : 0;
}
#end
Replace below line
[navigationController pushViewController:VideoDetailVC animated:YES];
With
[navigationController pushViewController:VideoDetailVC animated:NO];
It may solve your issue.

Objective c i want to hide my navigationbar but i want to show navigationItem's rightBarButtonItem

i am new in objective-c .I am trying to hide navigationbar i used this code and it's work perfectly but problem is this when i hide navigationbar after i am failed to show navigationItem's rightBarButtonItem
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:YES];
self.navigationController.navigationBarHidden = YES;
// self.navigationItem.rightBarButtonItem.enabled = NO;
}
i am used this code for navigationItem
-(void)loadBackButton{
/*UIBarButtonSystemItemDone */
buttonItem = [[UIBarButtonItem alloc] initWithTitle:#"Done" style:UIBarButtonItemStyleDone target:self action:#selector(dismiss:)];
self.navigationItem.rightBarButtonItem = buttonItem;
}
- (void)dismiss:(id)sender {
NSLog(#"Dismis Done");
[self dismissModalViewControllerAnimated:YES];
//[self.view removeFromSuperview];
}
and my - (void)viewDidLoad are bellow
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
//for load navigationItem's
[self loadBackButton];
self.navigationItem.rightBarButtonItem.enabled = YES;
// Do any additional setup after loading the view from its nib.
}
Hiding NavigationBar will hide your rightBarButtonItem too. One of the possible solutions is that you make the Navigation Bar transparent. You can use following code to do so:
[self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.shadowImage = [UIImage new];
self.navigationController.navigationBar.translucent = YES;
self.navigationController.view.backgroundColor = [UIColor clearColor];

iOS How can I set transparent in Container viewcontroller

I had embed UIPageViewController in the Root Viewcontroller.
Like below photo .
But I want to set First,second View controller background transparent, and it's still can show view controller text 1 and 2.
So It will show Root background color(black) and the root view controller can swipe though the uipageviewcontroller.
My pageviewcontroller part code below:
- (void)viewDidLoad {
[super viewDidLoad];
self.delegate = self;
self.dataSource = self;
pageControl = [UIPageControl appearance];
pageControl.pageIndicatorTintColor = [UIColor lightGrayColor];
pageControl.currentPageIndicatorTintColor = [UIColor blackColor];
pageControl.backgroundColor = [UIColor clearColor];
UIViewController *p1 = [self.storyboard
instantiateViewControllerWithIdentifier:#"Intro1ID"];
UIViewController *p2 = [self.storyboard
instantiateViewControllerWithIdentifier:#"Intro2ID"];
myViewControllers = #[p1,p2];
[self setViewControllers:#[p1]
direction:UIPageViewControllerNavigationDirectionForward
animated:NO completion:nil];
self.modalPresentationStyle = UIModalPresentationCurrentContext;
self.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
}
Have anyone can teach me how to set the containerview background color transparent and can show 1 , 2 text?
(It is sample code, so that just 1, 2 text)
thank you very much.
This should do the trick:
[[p1 view] setBackgroundColor:[UIColor clearColor]];
[[p2 view] setBackgroundColor:[UIColor clearColor]];
The issue is that the background view of your UIViewController was not transparent.

UISearchBar animation issue

I have a UIViewController in which I want to show a tableview with the serchBar.
//viewDidLoad
_tableView = [[UITableView alloc] initWithFrame:CGRectMake(0,
0,
SCREEN_WIDTH(),
SCREEN_HEIGHT())
style:UITableViewStylePlain];
_tableView.delegate = self;
_tableView.dataSource = self;
[self.view addSubview:_tableView];
// adding uisearch bar
searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
_tableView.tableHeaderView = searchBar;
//
searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self];
searchDisplayController.delegate = self;
searchDisplayController.searchResultsDataSource = self;
The issue happens when I click inside the uisearch bar so that the animation starts and it looks like it has a 20px unwanted offset.
In your Storyboard, select the problematic controller, look at the Attributes tab and try to edit these settings:
Under Top Bars
Under Opaque Bars
I've solved a similar problem by unflagging these settings.
I found what is causing this issue. Seems that the animation gets messed up when you set navigationBar.translucent to NO. If you make your navigationBar translucent, everything should work fine, but this is definitely not an ideal solution. I'm going to try and find a workaround.
UITableView *_tableView = [[UITableView alloc] initWithFrame:CGRectMake(0,
64,
self.view.frame.size.width,
self.view.frame.size.height)
style:UITableViewStylePlain];
_tableView.delegate = self;
_tableView.dataSource = self;
[self.view addSubview:_tableView];
// adding uisearch bar
UISearchBar* searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
_tableView.tableHeaderView = searchBar;
//
UISearchDisplayController* searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self];
searchDisplayController.delegate = self;
searchDisplayController.searchResultsDataSource = self;
and I just embade my controller with UINavigationcontroller and its working quite well..
You can cancel animation by subclassing UISearchDisplayController and adding this:
- (void)setActive:(BOOL)visible animated:(BOOL)animated
{
if(self.active == visible) return;
[self.searchContentsController.navigationController setNavigationBarHidden:YES animated:NO];
[super setActive:visible animated:animated];
[self.searchContentsController.navigationController setNavigationBarHidden:NO animated:NO];
if (visible) {
[self.searchBar becomeFirstResponder];
} else {
[self.searchBar resignFirstResponder];
}
}
codyko gave me an idea. It was the because the navigation bar was no translucent. So I set it to translucent on this view controller and rest when I left with the following code:
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
self.navigationController.navigationBar.translucent = NO;
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.navigationController.navigationBar.translucent = YES;
}
Now that left the navigation bar on this controller slightly faded, so I added a UIView the same color as my navbar just behind it to make it look opaque. I know it isn't perfect but it works nicely.
As a reminder for anyone with similar issues. I needed to add this line that fixed things:
self.edgesForExtendedLayout = UIRectEdgeNone;
Why are you creating the searchBar programmatically instead of in the StoryBoard ?
I'm currently using searchBar, added in storyboard and it's work fine ( I have to change the contentOffset )
I have applied your code,, It works fine for me,, Just hide you navigation bar and start the search bar from y = 20, instead of y = 0;

Resources