undeclared navigation object? - iphone

already i am declared navigation object like this
UINavigationController *naviButtonpro;
#property (nonatomic, retain) IBOutlet UINavigationController *naviButtonpro;
and also declared #synthesize naviButtonpro;
self.naviButtonpro = [[UINavigationController alloc] initWithNibName:#"NaviButtonViewController" bundle:nil];
[self.window addSubview:self.naviButtonpro.view];
when i am using this method
-(IBAction)displayNextPage:(id)sender
{
dispNext *gotoback = [[dispNext alloc] initWithNibName:#"dispNextView" bundle:[NSBundle mainBundle]];
//UINavigationController *naviButtonpro = [[UINavigationController alloc] initWithNibName:#"NaviButtonViewController" bundle:nil];
[self.naviButtonpro pushViewController:gotoback animated:YES];
[gotoback release];
}
i am geting an error like this
Request for member 'naviButtonpro' in something not a structure or union
can u tell me the how to resolve this problem

2 things to note here.
Firstly, you aren't creating a UINavigationController. You need to alloc init it. You seem to have it in the code but its commented out.
Secondly, dispNext needs to subclass & inherit from UIViewController. Does it do this?

The first problem is where you are initializing the 'naviButtonpro' and second is
What kind of the class its inherited of your interface class ? is it UIView or UIViewController.

Related

Make a link for each UITableViewCell with another view

I'm new in iOS programming, and I want to do a simple thing. I saw several topics about my problem, but I don't understand why my code doesn't work...
I created a UIViewController subclass called details2ViewController, with a .xib
In my main view called ViewController.xib, I have a tableView
In ViewController.m, I added on the top : #import "details2ViewController.h"
In ViewController.m, I modified the didSelectRowAtIndexPath method like this :
details *det = [[details alloc] init];
[self.navigationController pushViewController:det animated:YES];
There is no warning, but no effect when I click on a cell... I precise that I'm working without mainStoryBoard.
note : Here's my previously post about this problem.
(Sorry if my english is awkward, I'm french... Thanks for your help !)
First of all check that you have properly wired your TableView's delegate to your ViewController's File Owner or not. TableView's -didSelectRowAtIndexPath method is a delegate method.
Secondly, I am not getting why are using details as a Class name when you already have imported details2ViewController.h. So, It looks like you should use details2ViewController instead details and your code should look like this :
details2ViewController *det = [[details2ViewController alloc] initWithNibName:#"details2ViewController" bundle:nil];
[self.navigationController pushViewController:det animated:YES];
Make sure that your ViewController is indeed embedded in a UINavigationController. If not then your self.navigationController will be nil.
Or you can go through An Introduction To UINavigationController.
if you are using Storyboard you can use this code.
- (void)tableView:(UITableView *)atableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
YourViewController *yourViewController = [storyboard instantiateViewControllerWithIdentifier:#"StoryBoardID"];
[self.navigationController pushViewController:yourViewController animated:YES];
}
Don't forget to set animated:BOOL to YES in last line.
You have to first define a property of navigation controller in your AppDelegate.h:
#property (strong, nonatomic) UINavigationController *controller;
Then in the AppDelegate.m file do this in the didFinishLaunchingWithOptions: method :
details2ViewController *controller=[[details2ViewController alloc] initWithNibName:#"details2ViewController" bundle:nil];
self.controller = [[UINavigationController alloc] initWithRootViewController:controller];
}
self.window.rootViewController=self.controller;
[self.window makeKeyAndVisible];
return YES;
Then in the details2ViewController.m in the didSelectRowAtIndexPath:
details2ViewController *det = [[details2ViewController alloc] initWithNibName:#"details2ViewController" bundle:nil];
[self.navigationController pushViewController:det animated:YES];
Do let me know if it work.. :) Thanks.

Get String From Parent ViewController?

I need to get an NSString from my parent view controller to its child view.
So I have 'ParentView' ----> 'ChildView'
And I need to get the string from ParentView to ChildView. I have tried adding a method which returns a string in my ParentView and calling it like so in the ChildView with no luck.
Doesn't work:
ViewController *vc = [[ViewController alloc] init];
startDateLbl.text = [vc string];
Any help as to how to achieve this would be appreciated, thanks.
The easiest way would be to set a property for your string in the child view.
#property (nonatomic, retain) NSString *childString;
Then pass your string from the parent view to the child view before or after you push the view onto the stack.
ViewController *vc = [[ViewController alloc] initWithNibName:#"ViewController"];
vc.childString = parentString;
[self.navigationController pushViewController:vc animated:YES]; // this assumes navController
This line ViewController *vc = [[ViewController alloc] init]; will create a new object.
Just giving you a simple code hope you get it
ChildViewController *viewController = [[ChildViewController alloc] initWithNibName:#"ChildViewController" bundle:nil];
[self.navigationController pushViewController:viewController animated:YES];
//here set your label, make sure startDateLbl has getter property
viewController.startDateLbl.text = [vc string];
Depending on the UIViewController type you may have access to the parent View Controller.
self.parentViewController.someString (see UIViewController documentation).

iPhone - pushViewController Issue

I have a root view controller which should load another view controller as soon as it is done loading (i.e. in the viewDidLoad method).
I am using the UINavigationController in order to push a new view controller onto the stack:
In my rootviewcontrollerappdelegate:
-(void) viewDidLoad{
LoginViewController* lvc = [[LoginViewController alloc]init];
[self.navigationController pushViewController:lvc animated:NO];
}
I have textfields and buttons in the view controller to be loaded. The above doesn't seem to work however...It loads just a blank grey screen and no UINavigation bar is present. If I comment out the second line (pushViewController line), then I see the navigation bar. So I think it is loading something, but the items in the view controller being loaded are not being shown...Any ideas why?
Check if navigationController is pointing to nil. If it does, try
[self.view addSubview:self.pushViewController.view]
I had the same problem and found the above solution here:
UIViewController -viewDidLoad not being called
Unless you're doing something tricky, you should be calling alloc on the LoginViewController class rather than a variable. Also, if you've set up LoginViewController in Interface Builder (as opposed to programmatically), you'll need to load it from an NIB:
LoginViewController *lvc = [[[LoginViewController alloc] initWithNibName:nil bundle:nil] autorelease];
[self.navigationController pushViewController:lvc animated:NO];
Have a look at initWithNibName:bundle: in the docs.
Not entirely sure what you are trying to achieve but when you instantiate LoginViewContoller it should probably look like this
LoginViewController* lvc = [[LoginViewController alloc]init];
Judging by the nature of your naming for your view controller, is your LoginViewController the first view controller for your UINavigationController?
If that is what you're trying to do, you should instead initialise your navigation controller with the LoginViewController as the root controller instead of pushing it onto the navigation stack.
UINavigationController has a method to do this:
- (id)initWithRootViewController:(UIViewController *)rootViewController
EDIT:
Well, one way you can go about it is like this.
In your application delegate .h file, you should have declared a UINavigationController.
#interface MyAppDelegate : NSObject <UIApplicationDelegate>
{
UINavigationController *navController;
}
#property (nonatomic, retain) UINavigationController *navController;
#property (nonatomic, retain) IBOutlet UIWindow *window;
#end
In your App Delegate didFinishLaunching:withOption: you can create an instance of your LoginViewController there, and use that to init your UINavigation controller as the root view controller
#import "LoginViewController.h"
#implementation MyAppDelegate
#synthesize navController;
#synthesize window = _window;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
LoginViewController *loginController = [[LoginViewController alloc] init];
navController = [[UINavigationController alloc] initWithRootViewController:loginController];
[loginController release];
[[self window] setRootViewController:navController];
[navController release];
[self.window makeKeyAndVisible];
return YES;
}
I probably have a typo here or there but that's one way I would go about doing it.

splitViewController with Two NavigationController linking protocols

EDIT: Added Source Project
--> I uploaded a sample project that clearly shows my dilemma which can be found here <--
I created a Split View-based Application. I then added a second UINavigationController to the DetailViewController inside the MainWindow.xib.
I then pop a new UIViewController Subclasses when a toolbar item is clicked. I use the following code to conduct the pop:
DocumentDetailVC *DetailViewController = [[DocumentDetailVC alloc] initWithNibName:#"DocumentDetailVC" bundle:[NSBundle mainBundle]];
[detailViewController.detailNavController pushViewController:DetailViewController animated:YES];
DocumentsVC *RRequestViewController = [[DocumentsVC alloc] initWithNibName:#"DocumentsVC" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:RRequestViewController animated:YES];
This works. The issue I am having is how do I pass information or function calls from the Main side of the Split View to the Detail side of the Split view?
If I present the UIViewController via the following method:
DocumentDetailVC *RRequestViewController = [[DocumentDetailVC alloc] initWithNibName:#"DocumentDetailVC" bundle:[NSBundle mainBundle]];
RRequestViewController.delegate=self;
RRequestViewController.modalPresentationStyle = UIModalPresentationCurrentContext;
[RRequestViewController setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[self presentModalViewController:RRequestViewController animated:YES];
[RRequestViewController release];
RRequestViewController = nil;
I am able to complete a reach back through a protocol as intended.
DocumentDetailVC, when loaded via the pushViewController, the hierarchy is as follows:
NSLog([NSString stringWithFormat:#"%#",self]);
//self = <DocumentDetailVC: 0x4e0d960>
NSLog([NSString stringWithFormat:#"%#",self.parentViewController]);
//self.parentViewController = <UINavigationController: 0x4e0ce30>
NSLog([NSString stringWithFormat:#"%#",self.parentViewController.parentViewController]);
//self.parentViewController.parentViewController = <UISplitViewController: 0x4e0d0f0>
Thank you for your assistance. This problem is consuming my life!
--> I uploaded a sample project that clearly shows my dilemma which can be found here <--
Ok, I know am very late for answer but this answer is, I think, perfect and working. Try it. Open your RootViewController.h, on the top write this line:
#import "Left.h"
#import "Right.h"
in #interface RootViewController write this lines
Left *lefty;
Right *righty;
after that declare property as,
#property (nonatomic, retain) Left *lefty;
#property (nonatomic, retain) Right *righty;
go to ROOTVIEWCONTROLLER.M file synthesize as,
#synthesize lefty;
#synthesize righty;
after that in RootViewController.m just replace your function with this one
- (IBAction)myBtnPushed{
NSLog(#"myBtnPushed");
lefty = [[Left alloc] initWithNibName:#"Left" bundle:[NSBundle mainBundle]];
righty = [[Right alloc] initWithNibName:#"Right" bundle:[NSBundle mainBundle]];
lefty.delegate=righty;
[self.navigationController pushViewController:lefty animated:YES];
[detailViewController.navigationController pushViewController:righty animated:YES];
}
in delloac write this,
[lefty release];
lefty = nil;
[righty release];
righty = nil;
It's done, run your app. I tested, it's done.

presentmodalviewcontroller not working properly in Application Delegate in iPhone

I'm using two UIViewController in Application Delegate and navigating to UIViewController using presentmodalviewcontroller. But Problem is that presentmodalviewcontroller works for first time UIViewController and when i want to navigate to second UIViewController using presentmodalviewcontroller then its showing first UIViewController.
The following is the code:-
-(void)removeTabBar:(NSString *)str
{
HelpViewController *hvc =[[HelpViewController alloc] initWithNibName:#"HelpViewController" bundle:[NSBundle mainBundle]];
VideoPlaylistViewController *vpvc =[[VideoPlaylistViewController alloc] initWithNibName:#"VideoPlaylistViewController" bundle:[NSBundle mainBundle]];
if ([str isEqualToString:#"Help"])
{
[tabBarController.view removeFromSuperview];
[vpvc dismissModalViewControllerAnimated:YES];
[viewController presentModalViewController:hvc animated:YES];
[hvc release];
}
if ([str isEqualToString:#"VideoPlaylist"])
{
[hvc dismissModalViewControllerAnimated:YES];
[viewController presentModalViewController:vpvc animated:YES];
[vpvc release];
}
}
Can Somebody help me in solving the problem?
You're making a new hvc and vpvc each time you run this function.
The first time through, I assume you call removeTabBar:#"Help", it makes a hvc and vpvc and then shows the correct one.
The second time you call it removeTabBar:#"VideoPlayList", you are making a new hvc and vpvc. This means that when you call hvc dismissModalViewController:YES]; you're not removing the one you added before, you're removing the new one that you just made which isn't being displayed at all!
To solve this you need to make your two controllers as properties in your app delegate and create them in the applicationDidFinishLaunching method.
Add these into your app delegate's .h file:
#class MyAppDelegate {
HelpViewController *hvc;
VideoPlaylistViewController *vpvc;
}
#property (nonatomic, retain) HelpViewController *hvc;
#property (nonatomic, retain) VideoPlaylistViewController *vpvc;
#end
and in your app delegate's .m file :
- (void)applicationDidFinishLaunching:(UIApplication *)application {
...
self.hvc = [[[HelpViewController alloc] initWithNibName:#"HelpViewController" bundle:nil] autorelease];
self.vpvc = [[[VideoPlaylistViewController alloc] initWithNibName:#"VideoPlaylistViewController" bundle:nil] autorelease];
...
}
and remove the first two lines in removeTabBar