I have a view controller called "Help". I placed a label on the view controller story board, but in simulation I couldn't see the label. I used REMenu to put a menu at the top of the view. I can see the menu bar, but I cannot see the label. Here are the files.
#import "Help.h"
#interface Help ()
#end
#implementation Help
#synthesize helpText1;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self.view setBackgroundColor:[UIColor whiteColor]];
self.navigationItem.leftBarButtonItem =
[[UIBarButtonItem alloc] initWithTitle:#"Back"
style:UIBarButtonItemStyleBordered
target:self
action:#selector(handleBack:)];
helpText1.text=#"Hiii";
helpText1.hidden=NO;
// Do any additional setup after loading the view.
}
-(void)handleBack:(id)otherView{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
ViewController *myVC = (Controller *)[storyboard instantiateViewControllerWithIdentifier:#"QRList"];
[self.navigationController pushViewController:myVC animated:YES];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
Here is the code that calls the "Help" view controller.When we click on the help option in the menu, it will call the "help" view controller.
REMenuItem *helpItem = [[REMenuItem alloc] initWithTitle:#"Help"
subtitle:nil
image:[UIImage imageNamed:#"Ic"]
highlightedImage:nil
action:^(REMenuItem *item) {
NSLog(#"Item: %#", item);
Help *controller = [[Help alloc] init];
[weakSelf setViewControllers:#[controller] animated:NO];
}];
The "Help" view controller is getting called but I couldn't see the label which I dragged on storyboard. I couldn't figure out the issue.
I guess, that your label is being at a wrong view. Probably, your pushed controller doesn't contain the label you put in your nib file. Try to add other objects and see what's happening. If the problem is that I just guessed, then find the exact controller, choose a view and put there the label. Hope you solve that!
Use debug, put breakpoints, to see where you lose label. Check your layouts, maybe...tie your lable to top Space to superView, leading or tralling space to supeView or bottom space to superView. And beginning Xcode 4.4 we don't need synthesize, each added default
Related
I'm appending code to an existing app to add a modal loginView, the old project does not use xib, and the new view controller does.
The present project load its rootViewController this way
- (void) loadView
{
// this should take up the entire screen...
UIView * view = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
view.backgroundColor = [UIColor blueColor];
self.view = view;
sideBar =
[[SideBarView alloc] init];
sideBar.rootViewController = self;
[self.view addSubview:sideBar];
pageView =
[[PageView alloc] initWithTitle:DataEntryTitle
client:client];
pageView.rootViewController = self;
//I added this to instantiate the new view controller
_aLoginView = [[LoginViewController alloc]initWithUser:aUser];
[self.view addSubview:pageView];
}
To launch the modal view controller I'm using this code.
-(void)viewDidAppear:(BOOL)animated{
_aLoginView.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentViewController:_aLoginView animated:YES completion:nil];
}
As long as I understand the reason for the modal LoginView appearing blank is that I'm creating a new instance of it, instead of calling the existing xib definition. Does someone know what should I do to reference the xib? The old project does not use storyboard, nor xib files.
Thanks,
With your info I think I'm doing something wrong in LoginViewController.m, but I don't know exactly what.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (id)initWithUser:(verifyUser *)aUser
{
self = [super initWithNibName:#"LoginViewController" bundle:[NSBundle mainBundle]];
if (self) {
// Custom initialization
_UserModel = aUser;
}
return self;
}
You want to create the view controller by loading it from the nib
[[LoginViewController alloc] initWithNib:#"nib file name" bundle:[NSBundle mainBundle]]];
If you want to keep your initWithUser: initializer you should be able to do
self = [super initWithNib:#"nib file name" bundle:[NSBundle mainBundle]];
The files owner of your xib is not set.
Open your xib and select the file owner option in the top left
Then on the right pane set the files owner to your view controller:
FOOTNOTE
As an aside, you don't need to set the frame of your view controller in viewDidLoad. It isn't a ViewControllers responsibility to evaluate its own size. A view controller is merely responsible for maintaining the relationship between the model and the view. It is the responsibility of the container or parent ViewController to set the size.
Happy coding
I have an application with a navigation bar that navigates from one view controller to the next.
When navigating to next view controller on some simulators and devices the back button title is "Back" and on some simulator and devices the back button title is the title of the first view controller.
I would really like to understand why?
This is not an issue of changing the text on the back button. The issue is that on some simulators and devices I see the "back" title and on some simulators and devices I see the title of the previous controller.
Tested on over 20 simulators and devices.
Here is the code:
App Delegate
#import "AppDelegate.h"
#import "FirstViewController.h"
#import "SecondViewController.h"
#interface AppDelegate ()
#property (nonatomic, strong) UINavigationController *navigationController;
#end
#implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
FirstViewController *firstViewController = [[FirstViewController alloc]
initWithNibName:nil
bundle:nil];
self.navigationController = [[UINavigationController alloc]
initWithRootViewController:firstViewController];
self.window = [[UIWindow alloc]
initWithFrame:[[UIScreen mainScreen]bounds]];
self.window.rootViewController = self.navigationController;
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
First View Controller
#import "FirstViewController.h"
#import "SecondViewController.h"
#interface FirstViewController ()
#property (nonatomic, strong) UIButton *btnDisplaySecondViewController;
#end
#implementation FirstViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
-(void)performDisplaySecondViewController:(id)paramSender{
SecondViewController *secondControllrt = [[SecondViewController alloc]
initWithNibName:nil bundle:nil];
[self.navigationController pushViewController:secondControllrt
animated:YES];
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = #"First Controller";
self.btnDisplaySecondViewController = [UIButton
buttonWithType:UIButtonTypeSystem];
[self.btnDisplaySecondViewController
setTitle:#"Display Seconf View Controller"
forState:UIControlStateNormal];
[self.btnDisplaySecondViewController sizeToFit];
self.btnDisplaySecondViewController.center = self.view.center;
[self.btnDisplaySecondViewController addTarget:self
action:#selector(performDisplaySecondViewController:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:self.btnDisplaySecondViewController];
UIImageView *imageView =
[[UIImageView alloc]
initWithFrame:CGRectMake(0.0, 0.0, 100.0f, 40.0f)];
imageView.contentMode = UIViewContentModeScaleAspectFit;
UIImage *image = [UIImage imageNamed:#"ios7_0135"];
[imageView setImage:image];
self.navigationItem.titleView = imageView;
}
Second View Controller
#import "SecondViewController.h"
#interface SecondViewController ()
#end
#implementation SecondViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = #"Second Controller";
}
When you set the title of the current view controller it will be set automatically in place of Back in the navigation bar when you move to the next view controller. And if you didn't set the title of the current view controller then iOS automatically shows the Back title.
To set the title of the view controller, use the following code:
self.title = #"<title>";
I think you will get this from the explanation.
This is an old question, but I found the same just a second ago. For me, it is a matter of display space. On my iPhone 5, in portrait, I get the short "Back" text, if I rotate the view, it will show the previous' controllers title.
There is a different behavior in iOS6 and iOS7. In iOS7 the title of your first controller will be changed to "Back" (on the left navigationItem in the second VC) if its length exceed 11 characters. In iOS6 the title of the navBar gets truncated and/or the title of the back item.
Hi you can check this one Please upward if your problem has been solve so that the other can be benifited from it.
When my app returns from gallery, it has the navbar's standard colors
Additionally, if you want to change the name of your back button to be different than that of the previous view controller's title, you can do so by creating a custom back button item on the navigation item of the controller being pushed onto the navigation controller stack:
custom UIBarButtonItem for back button
Apple's reference here for backBarButtonItem
I'm trying to get my app to go to the next screen. I eneded up creating a simple test app with 2 screens
On the first vue I have a button connected to the following code to call up the next screen
- (IBAction)atest:(id)sender {
if (mHome == nil)
mHome = [[cHome alloc] initWithNibName:#"cHome" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:mHome animated:YES];
}
I put a break point to make sure the code exicutes, it does but..... the next screen does not come up.
complete code
#import <UIKit/UIKit.h>
#interface cHome : UIViewController{
}
- (IBAction)atest:(id)sender;
#end
#interface cHome ()
#end
#implementation cHome
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (IBAction)atest:(id)sender
{
[self.navigationController popToRootViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
Just like to add onto Unkn0wn and demonstrate how I presented certain views in an app.
Add a storyboard id for your view controller
click on your view controller in your storyboard hierarchy
click the identity inspector
add a storyboard id as a string in the storyboard id box
I then did something like this in my code:
[self presentViewController:[self.storyboard nstantiateViewControllerWithIdentifier:#"Paint"] animated:NO completion:nil];
obviously, your identifier would not be "Paint" but that's what I used. This was my simplist approach, hope it helps good luck!
NOTE: I did not use navigation controllers in my app.
EDIT
would like to point out, that this method kind of makes the controller appear out of nowhere with no animation (I had special animation for my controls as a transition between view controllers so I didn't need to animate the controller itself)
If you want to push a view controller, you can easily create a push segue, from your first view controller to your second view controller, and then push using
[self performSegueWithIdentifier:#"yourSegueIdentifier" sender:self];
"push segues" can be created both via code or in your storyboard file.
You have a mistake in your code:
mHome = [[cHome alloc] initWithNibName:#"cHome" bundle:[NSBundle mainBundle]];
I think it's the nib name. It should be mHome not cHome.
mHome = [[cHome alloc] initWithNibName:#"mHome" bundle:[NSBundle mainBundle]];
You basically cannot push two of the same view controller on one navigation controller.
Please see the image below. Keep in mind I am using xcode 4.5.2 as well. I followed the example on JASidePanels from github Example #2 and I can't seem to get rid of this black box! Otherwise the SidePanel actually works as expected. =)
image of problem
My centerViewController and leftViewController also look the same (code below). But when I tried to do it like the example said to do it, I wasn't having any such luck, so I had to subclass the JASidePanelController:
centerViewController.h:
#import "JASidePanelController.h"
#interface centerViewController : JASidePanelController
#end
centerViewController.m
#import "centerViewController.h"
#interface centerViewController ()
#end
#implementation centerViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
Could I very well be missing something? I have commented out a few lines of code to remove the rightViewController on the main JASidePanelController itself, thinking that could be causing a problem and it just caused more issues. I don't have the code for the rightViewController from the example as I am just using the left and center. So I set the code back into its defaults and I am left with a black box over the app in my simulator.
Thanks in advance!
Don't inherit from JASidePanelController for your center view controller. Think of a JASidePanelController as a container view that can hold 3 view controllers. Here is an example from my AppDelegate one of my projects:
self.panelController = [[JASidePanelController alloc] init];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
UIViewController *centerViewController = [storyboard instantiateInitialViewController];
self.panelController.centerPanel = centerViewController;
self.panelController.delegate = centerViewController;
self.panelController.rightPanel = [[DBRightViewController alloc] init];
self.panelController.leftPanel = [[DBLeftViewController alloc] init];
Think of it this way, you need a single JASidePanelViewController, which will hold your other view controllers. This can be a subclass of JASidePanelViewController, but it is probably not needed so long as you store the reference to it somewhere. In my example I store the panelController as a property in my AppDelegate.
Then, each of your viewcontrollers will be subclasses of UIViewController.
(I know this has been asked before, unfortunately none of the related StackOverflow answers I've looked through and tried out while trying to figure this problem out have worked for me. Any help would be much appreciated.)
I'm building a simple news app. The opening screen grabs the latest news entry using Parse's API.
And when you tap the menu button, you get a UITableView of past news days:
I want to be able to pass the id from the selected Parse table cell back to the main view.
I'm using ECSlidingViewController for the sliding menu and a Storyboard for the various screens:
But because of the way I'm using ECSlidingViewController, I can't figure out how to pass data via segues like I otherwise would be able to, so I'm trying to just pass it via the view controllers with a custom init.
Here's my MainViewController.h code:
#interface MainViewController : UIViewController
#property (nonatomic) NSString *detailId;
- (id)initWithDetailId:(NSString*)theId;
#end
Here's my didSelectRowAtIndexPath code in MenuViewController.m:
MainViewController *mainVC = [[MainViewController alloc] initWithDetailId:#"test"];
[self.navigationController pushViewController:mainVC animated:YES];
Here's MainViewController.m's initWithDetailId:
- (id)initWithDetailId:(NSString*)theId
{
NSLog(#"initWithDetailId");
self = [super initWithNibName:nil bundle:nil];
if (self) {
detailId = theId;
}
return self;
}
And here's MainViewController.m's viewDidLoad:
- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(#"detailId equals: %#", self.detailId);
}
But all I get from the NSLog is "detailId equals: (null)". What am I doing wrong here? Thanks!
you have forgot to put self. in front of detailId = theId;
self.detailId = theId;
that is
- (id)initWithDetailId:(NSString*)theId
{
NSLog(#"initWithDetailId");
self = [super initWithNibName:nil bundle:nil];
if (self) {
self.detailId = theId;
}
return self;
}
there is one another method of doing this:
MainViewController *mainVC = [self.storyBoard instantiateViewControllerWithIdentifier:#"yourIdentifier"];
mainVc.detailId=#"test";
[self.navigationController pushViewController:mainVC animated:YES];