I'm using this code in all ViewControllers to create back button:
self.btnBack = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 60, 44)];
[self.btnBack setBackgroundImage:[UIImage imageNamed:#"back.png"] forState:UIControlStateNormal];
[self.btnBack addTarget:self action:#selector(cancel:) forControlEvents:UIControlEventTouchUpInside];
-(void)cancel:(id)sender
{
[self.navigationController popViewControllerAnimated:YES];
}
But when I go to controller with UIWebView I need top tap 2 times to go back in ios 6.
And in ios 7 when I tap 1 time UIWebView disappeared show black screen with my navigation and on 2nd tap app crashes.
In all screen this works great maybe something special with UIWebView, I dont know.
Help please!
I push webview:
-(IBAction)doPrivacy:(id)sender
{
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
WebPageViewController *web = (WebPageViewController*)[storyBoard instantiateViewControllerWithIdentifier:#"WebPage"];
web.hidesBottomBarWhenPushed = YES;
web.urlToOpen = #"http://dfdfdf.co";
[self.navigationController pushViewController:web animated:YES];
}
I'm calling the same segue twice, you can fix this by unlinking the connection from the CELL DIRECTLY, to your segue, and having the segue connection originate at the top of the table hierarchy in IB, rather than nested inside the cell. Connect the segue from you View Controller itself, to the segue. If you have done this correct, when you select the segue, it should highlight the ENTIRE view it is coming from, not just the cell.
Related
I have created a utility app that links by button to another xib called scene - I am trying to create a navigation control for that link. When the button is clicked to then have a 'back' button on my scene xib. I don't wish to have a navigation bar visible on the Main View Controller or the Flipside View Controller. I'm quite new to iOS and I have no idea how to do this?
Would it maybe just be better to have a button going back to menu on a custom HUD? I don't know if that can be done?
Thank you for any help in advance, and thank you for your time
you could create a custom UINavigationBar on your scene xib, and add the custom back button to it if you don't want to create NavigationController , alternate would be that you could just make your first view as NavigationController and push the Scene view over it and it will brings the back button on the child view which is scene, keep your navigationBar hidden when you are on MainViewController and show only on scene view.
For hide UINavigationBar:
[[self navigationController] setNavigationBarHidden:YES animated:YES];
And Your can crate Custom UIButton and put anywhere (As Your requirement).
and in its method, Write code for go back to UIViewController (previous UIVieController).
Such like,
UIButton *btnBack = [UIButton buttonWithType:UIButtonTypeCustom];
[btnBack addTarget:self action:#selector(goBack:) forControlEvents:UIControlEventTouchUpInside];
btnBack.frame = CGRectMake(10, 10.5, 36, 39); // change it , As your wish
[btnBack setBackgroundImage:[UIImage imageNamed:#"MMBack.png"] forState:UIControlStateNormal];
[self.view addSubview:btnBack];
// call method of UIButton
-(void)goBack:(UIButton *) Sender
{
[self.navigationController popViewControllerAnimated:YES];
}
I have an UINavigationController and the first view is an UIView. I've setup two buttons and each one pushes another view , both UITableViewControllers.
The first buttons works just fine. The problem is: when I'm in the second TableViewController and I tap on the back button it tries to push the view again and only the second time it goes back to the Main View.
I also have an UITabBarController setup and I noticed that if I am in my first tab(the Main View with the two buttons pushing the two tableviews and precisely in the second view ) and i tap on another tab then tap back on the first - it shows me the content of my first UITableViewController and when I tap back it shows the second UITableViewController(that is supposed to be displayed) and only the second time i tap it goes to the Main View.
I don't know if it's understandable what I just said, here is also the code for the back button and the action for it:
- (void)viewDidLoad {
[super viewDidLoad];
UIButton *back= [UIButton buttonWithType:UIButtonTypeCustom];
UIImage *backImage = [[UIImage imageNamed:#"backb.png"]
stretchableImageWithLeftCapWidth:10 topCapHeight:10];
[back setBackgroundImage:backImage forState:UIControlStateNormal];
[back addTarget:self action:#selector(cancel:)
forControlEvents:UIControlEventTouchUpInside];
back.frame = CGRectMake(0, 0, 37, 26);
UIBarButtonItem *cancelButton = [[[UIBarButtonItem alloc]
initWithCustomView:back] autorelease];
self.navigationItem.leftBarButtonItem = cancelButton;
}
-(IBAction)cancel:(id)sender{
[self.navigationController popViewControllerAnimated:YES];
}
The back button in the first UITableViewController is setup the same and works just fine...what could be the problem?
I've just added another UITableViewController and obviously now when I'm in the third view and I try to go back to the Main View it loads the view two times and the first UITableViewController before it goes back...
There are chances that you have pushed the second view controller twice. While you push multiple instances of view controllers at the same time, you won't see any difference in the pushing animation. It'd look like only one controller is being pushed. This is because you push the next view controller before the previous view controller was pushed completely.
Check your code if you are pushing the second view controller twice.
I am a newbie in iPhone app development.
I want to develop a iPhone app as when the app is launched there are two buttons displayed for the user.
Button 1 is for User Login .
Button 2 is for User Registration .
How to add view to each of the button, where if Login button is pressed then that view is loaded with few textfields and a button to login in whereas if Registration button is pressed then the registration view is loaded with few textfields and a button to confirm registration.
There are few tutorilas of multiple views but they have only one button on one view and pressing that button the next view is loaded with one button to load the next view and so on and so forth. In my case I want many buttons (atleast 2 at the moment) on one view while app is loaded and then depending upon the button pressed that view is loaded.
Any sample code or tutorial link will be much appreciated.
Thanks in advance.
make one method and registered button event to this method
[button1 addTarget:self
action:#selector(buttonClicked:)
forControlEvents:UIControlEventTouchUpInside];
[button2 addTarget:self
action:#selector(buttonClicked:)
forControlEvents:UIControlEventTouchUpInside];
for e.g:
-(IBAction)buttonClicked : (id)sender
{
UIButton * btn = (UIButton *)sender;
if (btn == button1) {
LoginViewController * controller = [[LoginViewController alloc] initWithNibName:# "LoginViewController" bundle:nil];
[self.navigationController pushViewController : controller animated : YES];
[controller release];
} else if (btn == button2) {
RegisterViewController * controller = [[RegisterViewController alloc] initWithNibName:# "RegisterViewController" bundle:nil];
[self.navigationController pushViewController : controller animated : YES];
[controller release];
}
}
you want to make the views in interface builder, then on button one, you will use code like
ViewControllerSubClass1 *viewController1=[[ViewControllerSubClass1 alloc] initWithNibName:#"nibname1" bundle:nil];
[self.navigationController pushViewController:viewController1];
[viewController1 release];
for button two you would use
ViewControllerSubClass2 *viewController2=[[ViewControllerSubClass2 alloc] initWithNibName:#"nibname2" bundle:nil];
[self.navigationController pushViewController:viewController2];
[viewController2 release];
I currently have a window with a view attached that has three UIButtons. When the user presses a button, I would like the view to change to a new view using a NavigationController.
So right now I have the about button coded like so:
UIButton *aboutButton = [UIButton buttonWithType:UIButtonTypeCustom];
aboutButton.frame = CGRectMake(236, 240, 60, 60);
[aboutButton setImage:[UIImage imageNamed:#"About.png"]
forState:UIControlStateNormal];
[aboutButton addTarget:self action:#selector (aboutButtonPressed)
forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:aboutButton];
And for the action function:
-(void)aboutButtonPressed {
UINavigationController *aboutView =[[UINavigationControlleralloc] initWithNibName:#"About" bundle:nil];
[self.navigationController pushViewController:aboutView animated:YES];
[self.view addSubview:aboutView.view];
[aboutView release];
}
The About.xib file currently has nothing in it.
Now on to the problem... When the button is pressed a top navigation bar appears at the top but not in the animated sense like I have it coded. It just pops up. Also there is no back button to return to the view with the buttons on them. What am I doing wrong? I can provide more code or details if this is not clear enough.
Edit: Here is a picture to better understand what is happening.
After clicking the about button:
http://dl.dropbox.com/u/1481176/Screen%20shot%202010-12-09%20at%2011.28.40%20AM.png
Edit 2: Removed some wonky code for a back button that shouldn't of been there.
Most of the code after pushViewController looks dodgy.
-(void)aboutButtonPressed {
AboutViewController *aboutView =[[AboutViewController **alloc**] initWithNibName:#"About" bundle:nil];
[self.navigationController pushViewController:aboutView animated:YES];
[aboutView release];
}
That should at least push your empty view onto the stack and give you a back button automatically.
I'm creating a simple modal ViewController. I'm creating a nib with a button and on that button press calling a method to display modal viewController in which I'm creating the viewController and a button inside it like this.
UIViewController *modalViewController = [[UIViewController alloc]initWithNibName:nil bundle:nil];
modalViewController.view.backgroundColor = [UIColor redColor];
modalViewController.;
UIButton *btnDismissViewController = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btnDismissViewController.frame = CGRectMake(60, 160, 150, 50);
[btnDismissViewController setTitle:#"DISMISS" forState:UIControlStateNormal];
[btnDismissViewController addTarget:self action:#selector(dismissViewCOntroller) forControlEvents:UIControlEventTouchUpOutside];
btnDismissViewController.backgroundColor = [UIColor grayColor];
[modalViewController.view addSubview:btnDismissViewController];
[self presentModalViewController:modalViewController animated:YES];
This view is appearing properly but after pressing the button on modalViewController, the target method for dismissing the modalViewController isn't called. I'm definitely missing something obvious but not getting what. Can anybody please help?
Thanx in advance.
I agree with Ole's comment... additionally, make sure you are dismissing it within your dismissViewCOntroller method similar to this:
[self.parentViewController dismissModalViewControllerAnimated:YES];
I think there might be a typo in your code, dismissViewCOntroller seems like it should be dismissViewController, but maybe that was intentional, and the control state should be UIControlEventTouchUpInside.