Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am new in iOS development. I want move from one view to another view using UINavigationController. Please tell me if it possible or not, if possible than How??
Try this following code :
SecondVC *detailView = [[SecondVC alloc] initWithNibName:#"SecondVC" bundle:nil];
[self.navigationController pushViewController:detailView animated:YES];
[detailView release];
Use Following way :
.h file
#import "SecondViewController.h"
.m file
- (IBAction)gotoSecondView:(id) sender
{
NSLog(#"I am going to Second View");
SecondViewController *SecondView = [[SecondViewController alloc]initWithNibName:#"SecondViewController" bundle:nil];
[self.navigationController pushViewController:SecondView animated:YES];
[SecondView release];
}
For storyboard :
SecondViewController* SecondView = [self.storyboard instantiateViewControllerWithIdentifier:#"SecondViewController"];
[self presentModalViewController:SecondView animated:YES];
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
My project architecture is a 'Master Detail' and i want to show a footer through out all the viewcontrollers or tableviewcontrollers that i navigate.
Please help me to find the way.
You have to add the custom view to the window as a subview. It will display in all screens of the project as a footer. It'll work perfectly unless your application support orientation.
you can add it this way and instead of UIView use your customView's object to achieve your goal.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
self.viewController = [[[ViewController alloc] initWithNibName:#"ViewController" bundle:nil] autorelease];
self.navMain = [[UINavigationController alloc] initWithRootViewController:self.viewController];
self.window.rootViewController = self.navMain;
[self.window makeKeyAndVisible];
UIView *viewFooter = [[UIView alloc] initWithFrame:CGRectMake(0, 431, 320, 49)];
[viewFooter setBackgroundColor:[UIColor redColor]];
[self.window addSubview:viewFooter];
[self.window bringSubviewToFront:viewFooter];
return YES;
}
You have to use one root controller with footer, and content view. Add other view controllers as child of root view controller and views as subview of the content view.
I wrote a post about it, you can find it here:http://antrix1989.blogspot.com/2013/09/uiviewcontroller-as-singleton.html
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I am trying to allow the user to take a photo using UIImagePickerController and after finishing take him to a UITableView, passing the chosen image, where he can add info about the photo in text fields such as description.
Right now this is my code in didFinishPickingMediaWithInfo:
if (image) {
PhotoInfoViewController* photo_info_controller = [[PhotoInfoViewController alloc] init];
photo_info_controller.image = image;
[self dismissViewControllerAnimated:YES completion:^{
[self.parentViewController presentViewController:photo_info_controller animated:YES completion:nil];
}];
}
This takes the code to the next view which is a static tableviewcontroller
and in the PhotoInfoView controller
I see that viewDidLoad gets called by NSLog but all I see is an empty tableViewController and no text fields...
Any one have any advice??
Try to change PhotoInfoViewController initialization.
Set storyboard id in your storyboard file to PhotoInfoViewController
Change code.
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:<#name of storyboard#> bundle:[NSBundle mainBundle]];
PhotoInfoViewController *photo_info_controller = [storyboard instantiateViewControllerWithIdentifier:#"PhotoInfoViewController"];
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
I have this code that works great, but out of curiosity how can I replace the word self in this method?This is a navigation app btw, and been trying all sorts of methods to replace it.
Viewcontroller1
[self.navigationController popViewControllerAnimated:YES];
Here is one method I tried,
UIViewController *vc;
vc = [[Viewcontroller1 alloc] initWithNibName:nil bundle:nil];
[vc.navigationController popViewControllerAnimated:YES];
It is not possible to replace self. Because self is a keyword like this keyword in JAVA.
IN SHORT Apple/iOS Does not provede any types of Feature That any people can change it.
**EDIT**
From Your Code :
UIViewController *vc;
vc = [[Viewcontroller1 alloc] initWithNibName:nil bundle:nil];
[vc.navigationController popViewControllerAnimated:YES];
The best way for create object of Viewcontroller1 and navigate to another viewController for write as
Viewcontroller1 *objVC = [[Viewcontroller1 alloc] init];
[self.navigationController pushViewController: objVC animated:YES];
You are wrongly interpreting below line of code.
[self.navigationController popViewControllerAnimated:YES];
This line basicaly what does . it does remove from the viewController form current NavigationViewControlelr's (i.e self.navitionController )Stack
stack-- basically when you create any viewController and that view Controller into the navigationController, then navigation controller add that viewController according to the Stack or can say manage the ViewController in stack's Way.
And About the your below line of code
UIViewController *vc;
vc = [[Viewcontroller1 alloc] initWithNibName:nil bundle:nil];
[vc.navigationController popViewControllerAnimated:YES];
Why u are creating ViewController removing form the navigationViewController. it'll craete memory overhead
and About replacing the self. you can't replace self as `iPatel' told above.
When you say you want to replace self with "an object or something", self is an object. The word self refers to the current instance of the class that the function is in. You cannot replace self because then you would not be referencing the current instance of your UIViewController subclass.
Why your example does not work:
UIViewController *vc;
vc = [[Viewcontroller1 alloc] initWithNibName:nil bundle:nil];
[vc.navigationController popViewControllerAnimated:YES];
Is because it is referencing a new instance of the Viewcontroller1 class. The popover will not appear because you are not adding it to your current viewcontroller; you are adding it to another instance that is never displayed.
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
I've created an app that contains 4 viewcontroller and its .h,.m files...In my firstviewcontroller a button is pressed it goes to secondviewcontroller and in second viewcontroller has two buttons and its used to switch back to firstviewcontroller and another button will goes to thirdviewcontroller.here is my code for firstviewcontroller.m
[[NSBundle mainBundle] loadNibNamed:#"SecondViewController" owner:self options:nil];
and in my secondviewcontroller for first button
[[NSBundle mainBundle] loadNibNamed:#"FirstViewController" owner:self options:nil];
and another button
[[NSBundle mainBundle] loadNibNamed:#"ThirdViewController" owner:self options:nil];
when i select button in firstviewcontroller it loads secondviewcontroller but in second view controller if i select any button i get Sigabart warning...
Can anyone have idea about this...I've tried so many ways..
You can use following approaches to perform these tasks :
Approach 1:
In FirstViewController.m write this code at button click :
SecondViewController *secondVC = [[SecondViewController alloc]initwithNibName:#"SecondViewController" bundle:nil];
[self.view addSubView:secondVC.view];
This will add the secondviewcontroller to current view
In SecondViewController.m to add third View you can write
ThirdViewController *thirdVC = [[ThirdViewController alloc]initwithNibName:#"ThirdViewController" bundle:nil];
[self.view addSubView:thirdVC.view];
and to remove the second view you can write this:
[self.view removeFromSuperview];
Approach 2:
Use Navigation Controller.
use code like this
FirstViewController *FVC = [[FirstViewController alloc] initWithNibName:#"FirstViewController" bundle:nil];
//For Push
[self.navigationController pushViewController:FVC animated:YES];
//For Pop
[self.navigationController popViewControllerAnimated:YES];
:)
In iPhone app programming viewControllers are generally store in a stack one by one as we push a view controller to a new another view controller. and view remove these controller in same reverse formate. so if u want to push a new view controller use this:
SecondViewController *second = [[SecondViewController alloc]
initWithNibName:#"SecondViewController" bundle:nil];
[self.navigationController pushViewController:second animated:YES];
and if u want to remove current view controller use this :
`[self.navigationController popViewControllerAnimated:YES] ;
if u want to jump to ur first view controller from any of the view controller
[self.navigationController popToRootViewControllerAnimated:YES];
you can get the viewcontrollers presented in this stack by this line of code
NSArray *viewArr = [self.navigationController viewControllers];
NSLog(#"%#",viewArr);
[self.navigationController popToViewController:[viewArr objectAtIndex:1] animated:YES];
`
//For going in forword direction you can use this block
{
FirstViewController *firstVC = [[FirstViewController alloc] initWithNibName:#"FirstViewController" bundle:nil];
[self.navigationController pushViewController:firstVC animated:YES];
[firstVC relese];
}
//For returning back you can use this block
{
[self.navigationController popViewControllerAnimated:YES];
}
//But before using this line of code you have to alloc and make the property of navigationController in your appDelegate
Hope this will help you
I'm still facing the problem when I launch my application in iPhone.
It shows the stack over flow by presentModelViewController because I'm using number of viewcontroller and calling the same viewcontroller from other viewcontroller but it gets terminated. Here I'm showing the code which I'm using in whole program to call other view controller
UV_AlarmAppDelegate *app7 = (UV_AlarmAppDelegate *)[[UIApplication sharedApplication]delegate];
[self presentModalViewController:app7.frmComparisionChartLink animated:YES];
[app7 release];
Still I'm releasing the pointer but still my app gets terminated.
You shouldn't release the app delegate. In short, unless you alloc, copy or retain an object you don't need to release it.
Apple's documentation shows modalPresentation done like this;
UIViewController *uiViewController = [[UIViewController alloc] initWithNibName:#"UIViewController" bundle:nil];
uiViewController.delegate = self;
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:uiViewController];
[self presentModalViewController:navigationController animated:YES];
[navigationController release];
[uiViewController release];
Hopefully that helps.