Why can't I segue to a view controller in my XIB? - ios

In my code below, I am getting an error saying "Property "navigationController" not found on object of type 'iPhoneFirstPageView *'. This worked before in a different project, but it won't work in this XIB. Any ideas?
-(IBAction)Twitter {
TwitterViewController *twitter = [[TwitterViewController alloc] initWithNibName:nil bundle:nil];
//[self presentViewController:twitter animated:YES completion:NULL];
//[self presentModalViewController:twitter animated:YES];
[self.navigationController pushViewController:TwitterViewController animated:YES];
}

Your first problem is that on this line:
[self.navigationController pushViewController:TwitterViewController animated:YES];
You are trying to push the CLASS TwitterViewControllerrather than your object twitter
Your second problem is that iPhoneFirstPageView is a subclass of UIView and not of UIViewController. The cleanest way for someone new to fix this would be in Xcode to create a new file called iPhoneFirstPageViewController that is a subclass of UIViewController.
The solution setup your initial view controllers as the follow:
iPhoneFirstPageViewController *firstViewController = [[iPhoneFirstPageViewController alloc] init];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:firstViewController];
////Skip to the method you are trying to write. This will be in iPhoneFirstPageViewController.m
-(IBAction)Twitter
{
TwitterViewController *twitter = [[TwitterViewController alloc] init];
[self.navigationController pushViewController:twitter animated:YES];
}

Related

Xcode UIViewController to customUIViewController without IB

I have a UIViewController, and inside that view controller I would like to call a CustomUIViewController without the use of Interface Builder. I've been using this and it works but it requires a storyboard ID.
UIStoryboard *storyboard = self.storyboard;
UIViewController *myVC = (UIViewController *)[storyboard instantiateViewControllerWithIdentifier:#"PageID"];
[self presentModalViewController:myVC animated:YES];
Is there a way of going from a UIViewController to a customViewController without the use of segues and IB?
Use this:
UIViewController *myVc = [[UIViewController alloc] init];
[self presentViewController:myVc animated:YES completion:nil];
This will obviously present a new blank view controller, if you want your PageID view then you replace UIViewController with the name of the PageID class (i,e the .h/.m file names)
So i'm assuming this:
PageID *myVc = [[PageID alloc] init];
[self presentViewController:myVc animated:YES completion:nil];
If you want it inside a navigation controller do:
PageID *myVc = [[PageID alloc] init];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:myVc];
[self presentViewController: navController animated:YES completion:nil];
OR if you don't want it to be modal (don't need to create a new navigation controller as it will be added to the existing navigation controller stack i.e. [self navigationController]:
[[self navigationController] pushViewController:myVc animated:YES];

Popover is shown null

I'm trying to show a popover with a title, creating a root view controller and instantiating it with my viewController. But, when I show the popover, the content is not shown. Here is the code:
UIViewController *popContentViewController = [[sb instantiateViewControllerWithIdentifier:#"videosTutoriais"] init];
UINavigationController *controller = [[UINavigationController alloc] initWithRootViewController:popContentViewController];
_popover = [[UIPopoverController alloc] initWithContentViewController:controller];
_popover.delegate = self;
[popContentViewController release];
[controller release];
//dados.myPopoverController = popOverController;
[[self popover] presentPopoverFromRect:ancora.bounds inView:ancora permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
Just to be more specific, the title of popover appears normally, but the content doesn't.
Just double check that popContentViewController is not nil. You have the identifier #"videosTutoriais" which looks like it might be a scanning error.
From your code, you are releasing the controller before you display in on the screen. Try releasing it after or in the dealloc method. If you are unsure about memory management. I suggest you try ARC instead to avoid silly errors and mistakes such as this.
The code looked like this:
sb = [UIStoryboard storyboardWithName:#"MainStoryboard_iPad" bundle:nil];
UINavigationController *controller = [[sb instantiateViewControllerWithIdentifier:#"navTutorial"] init];
_popover = [[UIPopoverController alloc] initWithContentViewController:controller];
[[self popover] presentPopoverFromRect:ancora.bounds inView:ancora permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
[controller release];

unable to add UINavigationController to ModalViewController?

I am using a UIModalViewController in my project where I am unable to add a UINavigationBar at the top. I am also using other UIModalViewControllers in my project where I am successful with adding UINavigationBar. The only difference between the unabled UIModalViewController and the others is, it is linked to several other ViewControllers (all using a modal "push" to it) where the other ModalViewControllers are just linked to 1 other ViewController.
I am using the following code when I am trying to add a UINavigationController to it:
ShowTaskViewController *detailViewController = [[ShowTaskViewController alloc] init];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:detailViewController];
navController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self.navigationController presentModalViewController:navController animated:YES completion:nil];
[navController release];
[detailViewController release];
But no bar gets added. I am not getting any errors or anything. Any Idea what may have happened here ?

adding an UINavigationController to a UIControllerView

i was searching this whole afternoon in hope of solution but i didn't manage to find anything helping me solve the problem.
The problem is, i have no intention of using UINavigationController until a button gets taped, and after that i would like to present view controller containing a navigationcontroller, or reverse, modally. in my search i came across this solution:
MyExampleViewController *vc = [[[MyExampleViewController alloc] initWithNibName:#"MyExample" bundle:nil] autorelease];
UINavigationController *navController = [[[UINavigationController alloc] initWithRootViewController:vc] autorelease];
[self presentModalViewController:navController animated:YES];
which i then used it in my code and found out it is not working, to make sure i started a practice project from viewbased project templet and added this to the first view controller
- (IBAction) buttonGotPreseed{
testino *testController = [[testino alloc] initWithNibName:#"testino" bundle:nil];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:testController];
testController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:testController animated:YES];
[nav release];
[testController release];
}
didn't work also, im not seeing the navigation bar up there
any help would be greatly appreciated
You're pushing the root view controller, not the navigation controller itself. Line 5 should be:
[self presentModalViewController:nav animated:YES];

How to create view hierarchy programmatically?

I usually create my view hierarchy's in IB but this time I need to do it in my code. Basically I already have my custom view but I want it to be contained inside a UINavigationController. So how can I do that?
If you wish to nest it in a Navigation controller you should use :
UIViewController * myViewController = [[GameController alloc] init];
myViewController.view = yourCustumeView;//if you are trying to add a UIView
UINavigationController *navigationController = [[UINavigationController alloc]
initWithRootViewController:myViewController];
[self.navigationController pushViewController:navigationController animated:YES];
[navigationController release];
[myViewController release];
Good luck
EDIT
add this code (before the release):
navigationController.navigationItem.leftBarButtonItem=nil;//change it to rightBarButtonItem if the button is on the right.
If you want to create several ViewControllers then you can allocate them in code and then in order to show them just push it like this:
RegistrationViewController * regView= [[RegistrationViewController alloc] init];
[self.navigationController pushViewController:regView animated:YES];

Resources