Can't Set Title of NavigationBar - title

self.title = #"title";
self.navigationController.title = #"title";
self.navigationItem.title = #"title";
self.navigationController.NavigationItem.title = #"title";
Nothing changes the Title. What can I do?

this is how I made it in the MainTabBarController, but I can't change it for example in the SettingsViewController.
- (void)viewDidLoad {
[super viewDidLoad];
UINavigationBar *navbar = [[UINavigationBar alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 60)];
UINavigationItem *navItem = [UINavigationItem alloc];
navItem.title = #"Test";
navbar.translucent = NO;
[navbar pushNavigationItem:navItem animated:false];
[self.view addSubview:navbar];
}

My Solution was to make in every ViewController it's own NavigationBar and hide the NavitagionBart from the MainTabController.

Related

TabBar with center button

Hi, I'd like to make a tabBar with center button. As we can see from the image, when I clicked the tabbar, it will show me a view to select buttons. When I clicked the "notes" button, the view will disappear and my app will jump to the correspond viewcontroller and the tabbar.selectIndex = 2. I already made a subclass of UITabBarController, and add a button to the view, the code is like this [self.view addSubview:middleButton]. Now the problem is, when I push viewcontroll, the tabbar disappear while the center button still on the page. And when I go back to the main viewcontroller, the tabbar will overlap the center button. I don't want to make a whole custom UITabBarViewController, please tell me how to hide the center button when push viewcontroll and how to show it on the tapbar when I go back to the main viewcontroller.
Hi, Hament, I have not use method "-(void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item". My code is as below:
#implementation MyTabBarController
- (void)viewDidLoad {
[super viewDidLoad];
[self setupViews];
[self setupTabBarItems];
[self setupMiddleButton];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)setupViews
{
mask = [[NSBundle mainBundle] loadNibNamed:NSStringFromClass([MyMiddleButtonMask class]) owner:self options:nil].firstObject;
mask.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
mask.delegate = self;
}
-(void)setupTabBarItems
{
UIViewController *vc1 = [[UIViewController alloc] init];
vc1Nav = [[UINavigationController alloc] initWithRootViewController:vc1];
UIViewController *vc2 = [[UIViewController alloc] init];
vc2Nav = [[UINavigationController alloc] initWithRootViewController:vc2];
UIViewController *vc3 = [[UIViewController alloc] init];
vc3Nav = [[UINavigationController alloc] initWithRootViewController:vc3];
UIViewController *vc6 = [[UIViewController alloc] init];
vc6Nav = [[UINavigationController alloc] initWithRootViewController:vc6];
UIViewController *vc7 = [[UIViewController alloc] init];
vc7Nav = [[UINavigationController alloc] initWithRootViewController:vc7];
self.viewControllers = #[vc1Nav, vc2Nav, vc3Nav, vc6Nav, vc7Nav];
}
-(void)setupMiddleButton
{
middleButton = [[UIButton alloc] initWithFrame:CGRectMake(0, -16, 64, 64)];
CGRect f = middleButton.frame;
f.origin.y = SCREEN_HEIGHT - f.size.height;
f.origin.x = (SCREEN_WIDTH - f.size.width)/2;
middleButton.frame = f;
[middleButton setImage:[UIImage imageNamed:#"plus"] forState:UIControlStateNormal];
middleButton.backgroundColor = [UIColor redColor];
middleButton.layer.cornerRadius = middleButton.frame.size.height/2;
[self.view addSubview:middleButton];
[middleButton addTarget:self action:#selector(didClickedMiddleButton:) forControlEvents:UIControlEventTouchUpInside];
}
-(void)didClickedMiddleButton:(id)sender
{
[[UIApplication sharedApplication].keyWindow.rootViewController.view addSubview:mask];
}
#pragma mark - KGOMiddleButtonMaskDelegate, Button1,2,3 are on the mask page.
-(void)didClickedButton1:(KGOMiddleButtonMask *)maskView
{
self.viewControllers = #[vc1Nav, vc2Nav, vc3Nav, vc6Nav, vc7Nav];
self.selectedIndex = 2;
[maskView removeFromSuperview];
}
-(void)didClickedButton2:(KGOMiddleButtonMask *)maskView
{
self.viewControllers = #[vc1Nav, vc2Nav, vc4Nav, vc6Nav, vc7Nav];
self.selectedIndex = 2;
[maskView removeFromSuperview];
}
-(void)didClickedButton3:(KGOMiddleButtonMask *)maskView
{
self.viewControllers = #[vc1Nav, vc2Nav, vc5Nav, vc6Nav, vc7Nav];
self.selectedIndex = 2;
[maskView removeFromSuperview];
}
-(void)didClickedSelf:(KGOMiddleButtonMask *)maskView
{
[maskView removeFromSuperview];
}
-(void)didClickedCloseButton:(KGOMiddleButtonMask *)maskView
{
[maskView removeFromSuperview];
}

UISearchBar inside a NavigationBar Get Deferenced When Keyboard Shows Up

I'm putting a search bar inside a navigation bar. here is the code
self.navigationBar =[[UINavigationBar alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 64)];
[self.view addSubview:self.navigationBar];
self.doneButton = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemDone
target:self
action:#selector(doneButtonPressed)];
self.searchBar = [[UISearchBar alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 64)];
self.searchBar.autocorrectionType = UITextAutocorrectionTypeNo;
self.searchBar.placeholder = #"Name of City";
self.searchBar.delegate = self;
self.searchController = [[UISearchDisplayController alloc]initWithSearchBar:self.searchBar contentsController:self];
self.searchController.delegate = self;
self.searchController.searchResultsDelegate = self;
self.searchController.searchResultsDataSource = self;
self.searchController.searchResultsTitle = #"Add Location";
self.searchController.displaysSearchBarInNavigationBar = YES;
self.searchController.navigationItem.rightBarButtonItems = #[self.doneButton];
self.navigationBar.items = #[self.searchController.navigationItem];
but the search bar behaves incorrectly.
I'm expecting it would look like this
I've fixed this by bring the navigationBar to front after setting searchBar as the first responder
[self.searchController setActive:YES animated:NO];
[self.searchController.searchBar becomeFirstResponder];
[self.view bringSubviewToFront:self.navigationBar]; //this is the line I add

Cant set title or button inside UINavigationController

I inherit from UINavigationController now I want to set a button and my title in ViewDidLoad.
- (void)viewDidLoad
{
[super viewDidLoad];
self.toolbar.barStyle = UIBarStyleBlackOpaque;
self.navigationBar.barStyle = UIBarStyleBlackOpaque;
[self.navigationItem setTitle:#"TEST"];
[self setToolbarHidden:YES];
}
But i doesn't work, I think its something I miss.
For set title of UINavigationBar
use
self.title = #"TESTING";
and BarButton on NavigationBar
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:#selector(showActionsheet)] autorelease];

Issues with UISplitViewController and modal UIViewControllers

I have a really strange UI glitch in my iPhone/iPad app. Because I wanted to find the cause of it, I created a new project with as little code as possible. The important code is below.
Basically, I have a UISplitViewController containing two UIViewController subclasses. When a button is tapped, the first one presents modally and as UIModalPresentationFormSheet a UIViewController subclass called Modal. In there, when a button is tapped, another UIViewController subclass called Text is presented, this time as UIModalPresentationFullScreen. In Text, there is a UITextView. When it is tapped, everything is alright, but when the iPad is rotated, I get this:
The white part is the Text view controller, the red part in the background is ViewControllerTwo.
Does anybody have any idea why this happens? And what I can do to fix it?
Here is the Project: MediaFire
Here is the relevant source code:
// AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
ViewControllerOne *one = [[ViewControllerOne alloc] init];
ViewControllerTwo *two = [[ViewControllerTwo alloc] init];
UISplitViewController *split = [[UISplitViewController alloc] init];
split.viewControllers = [NSArray arrayWithObjects:one, two, nil];
self.window.rootViewController = split;
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
// ViewControllerOne.m
#import "Modal.h"
#implementation ViewControllerOne
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor blueColor];
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = CGRectMake(30, 30, 44, 44);
[button addTarget:self action:#selector(buttonTapped) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
}
- (void)buttonTapped
{
Modal *modalOne = [[Modal alloc] init];
modalOne.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentModalViewController:modalOne animated:YES];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
// Modal.m
#import "Text.h"
#implementation Modal
- (void)viewDidLoad
{
[super viewDidLoad];
UIButton *buttonOne = [UIButton buttonWithType:UIButtonTypeRoundedRect];
buttonOne.frame = CGRectMake(30, 30, 44, 44);
buttonOne.tag = 1;
[buttonOne addTarget:self action:#selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside];
UIButton *buttonTwo = [UIButton buttonWithType:UIButtonTypeRoundedRect];
buttonTwo.frame = CGRectMake(30, 100, 44, 44);
buttonTwo.tag = 2;
[buttonTwo addTarget:self action:#selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:buttonOne];
[self.view addSubview:buttonTwo];
}
- (void)buttonTapped:(UIButton *)button
{
if (button.tag == 1)
{
Text *text = [[Text alloc] init];
text.modalPresentationStyle = UIModalPresentationFullScreen;
[self presentModalViewController:text animated:YES];
}
else
{
[self dismissModalViewControllerAnimated:YES];
}
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
// Text.m
#implementation Text
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor greenColor];
UITextView *textView = [[UITextView alloc] initWithFrame:self.view.bounds];
textView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.view addSubview:textView];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
You may need to present the modal views from the UISplitViewController instead of it's subviews...
UISplitViewController *splitViewController = [(AppDelegate *)[[UIApplication sharedApplication] delegate] splitViewController];
[splitViewController presentModalViewController:modal animated:YES];

Adding a UILabel to UiTableViewCell - text is being cropped vertically

Running into a problem when I try and add a UILabel to a custom UITableViewCell. For some reason the frame's are not being respected at all - when I try and set the label height (through CGRectMake) the text is being cropped vertically. In other words, only half of the text is being shown.
When I play around with the CGRectMake's frame height it shows some strange behavior - sometimes a lower value will actually make things align properly.
Am I setting the wrong values? Is the frame the wrong property to be modifying?
Edit for code:
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if ((self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])) {
// Initialization code
eventName = [[UILabel alloc] initWithFrame:CGRectZero];
//eventName.backgroundColor = [UIColor blueColor];
eventName.numberOfLines = 2;
eventName.minimumFontSize = 8.;
eventName.adjustsFontSizeToFitWidth = YES;
eventName.text = #"Event Name";
[self.contentView addSubview:eventName];
eventStartEndDate = [[UILabel alloc] initWithFrame:CGRectZero];
eventStartEndDate.backgroundColor = [UIColor blueColor];
eventStartEndDate.text = #"Event Start and End Dates";
[self.contentView addSubview:eventStartEndDate];
description = [[UILabel alloc] initWithFrame:CGRectMake(10.0, 30.0, 300.0, 20.0)];
[self.contentView addSubview:description];
}
return self;
}
-(void)layoutSubviews
{
[super layoutSubviews];
if (!self.editing) {
eventName.frame = CGRectMake(10.0, 10.0, 300.0, 20.0);
eventStartEndDate.frame = CGRectMake(10.0, 35.0, 300.0, 20.0);;
}
}
First of all, you should pay more attention to memory management. You have to call release on your UILabels.
The reason, why your UILabels sometimes seem clipped is, because your other labels do have a white, opaque background. Setting the backgroundColor property to [UIColor clearColor] does the trick.
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
eventName = [[UILabel alloc] initWithFrame:CGRectZero];
//eventName.backgroundColor = [UIColor blueColor];
eventName.numberOfLines = 2;
eventName.minimumFontSize = 8.;
eventName.adjustsFontSizeToFitWidth = YES;
eventName.text = #"Event Name";
eventName.backgroundColor = [UIColor clearColor];
[self.contentView addSubview:eventName];
[eventName release];
eventStartEndDate = [[UILabel alloc] initWithFrame:CGRectZero];
eventStartEndDate.backgroundColor = [UIColor blueColor];
eventStartEndDate.text = #"Event Start and End Dates";
[self.contentView addSubview:eventStartEndDate];
[eventStartEndDate release];
description = [[UILabel alloc] initWithFrame:CGRectMake(10.0, 30.0, 300.0, 20.0)];
description.backgroundColor = [UIColor clearColor];
[self.contentView addSubview:description];
[description release];
}
return self;
}