Subscribe ( )

iPhone Programming Tutorials


 

Forum

You must be logged in to post Login Register

Search 

Display a view when button click

User Post

11:03 pm
October 3, 2008


judy

Noob

India

posts 1

1

Hi all,


         I want to display a new view when button click.

        Can anybody please tell me the code?


10:33 am
October 4, 2008


Admin

brandontreb

posts 88

2

Judy, 


have you gone through this tutorial?  To transition with a button is very similar.

iPhone Programming Tutorial – Connecting Code to An Interface Builder View

If debugging is the process of removing bugs, then programming must be the process of putting them in.
-Edsger Dijkstra

8:36 am
November 5, 2008


bitwise

Noob

bitwise

posts 2

3

I've went through that tutorial. It's not difficult to handle a button click event; however, what is the required code in the button click event to transition to a new view?

I am looking to do the same thing (i.e. switch to a new view when the user clicks a button).

10:11 am
November 5, 2008


piku9000

iCoder

posts 11

4

Hello, i've been following the tutorials that have been on the site and i've learned some stuff…

if you want to switch from one view to another, i suggest you this:


Let's say… you should have already a View created with IB and a ViewController on Xcode (your View should be binded with your ViewController by the way).
Bind a button to a method (that was on the tutorial posted by Brandon) and then put up this code on your main view Controller:

 

View2ViewController *view2 = [[View2ViewController alloc] initWithNibName:@”View2″ bundle:[NSBundle mainBundle]];

[self.navigationController pushViewController:view2 animated:YES];
[view2 release];

the first line is to create an instance of a view… you should use the initWithNibName method to specify whats the name of the xib file that contains your view, and i'm not quite sure about NSBundle… it reminds me of reflection on .net

the second line pushes your new view on top of the current one by using the navigationController class that's contained on the view.

and then the 3rd one is to release the view2 pointer… i find this task extremely complicated on a large scale… since there's no garbage collector

anyway i think thats it

3:24 am
November 6, 2008


tubier

Noob

posts 4

5

@Barandon:

I met also with this problem. this is not so simple like you said. This is not simple like  responsing to a normal button event. Because you must display a new view when button clicked, e.g. one creates a login UI to protect some sensible data. After the user gave the right password and then clicked the submitting button, a new view will be displayed to show the sensible data. 

I have gone throught your tutorial and have tried some relutions, but i can not resolv this problem.

thank you for your good tutorials, they are very helpful.


@ piku9000: I have tried with your idee, but it does not seem to be the right one. maybe I have anywhere error. I do not know. But thank you all the same. 

10:25 am
November 10, 2008


piku9000

iCoder

posts 11

6

yes, i tried it and it did not work :(

it seems that you DO need to have a navigation application in order to do this… or a working navigation controller, i think they thought it this way: “it would seem dumb to try to switch views if you aren't navigating between them”

the code i posted DOES push a new view. try creating a navigation application, then creating a new view, and replacing the tablelist view with your new view (which should have that button that creates a new view).

8:52 pm
November 17, 2008


richKing

Noob

posts 1

7

Hi Guys.. I also had this issue which stumped me for a while. Problem was the code shown in the tutorial link above is for the navigation controller.

But this is some code which I found did the trick.. very similar.

if(self.detailsViewController == nil){
        detailsView *detView = [[detailsView alloc] initWithNibName:@”detailsView” bundle:[NSBundle mainBundle]];
        self.detailsViewController = detView;
        [detView release];
    }
   
//This code pops up the window   
[self.view addSubview:self.detailsViewController.view];
Search 

About the iCodeBlog forum

Most Users Ever Online:

44


Currently Online:

6 Guests

Forum Stats:

Groups: 2

Forums: 6

Topics: 419

Posts: 893

Membership:

There are 935 Members

There has been 1 Guest

There are 2 Admins

There is 1 Moderator

Top Posters:

bobcubsfan – 54

crazyiez – 30

Uhu – 17

AdeC – 17

Nick – 15

jitesh61 – 12

Administrators: Brandon (88 Posts), Collin (0 Posts)

Moderators: VertigoSol (26 Posts)



©   

  • Posted by on 6 Aug 2008 in Uncategorized
  •   |  
  •   |  
  •   |  
  • Comments Off

Comments are closed.