Amazon.com Widgets Going to another class when clicking text?
Welcome, Guest. Please login or register.
Did you miss your activation email?
May 25, 2013, 06:45:36 PM
Home Help Search chat Login Register   
News: Read this please.The Great Kangaroo Escape Looking for reviews of the 4th ed on Amazon!   Twitter:  @skochan
                     

+  Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
|-+  Old Stuff
| |-+  Help!!!
| | |-+  Going to another class when clicking text?
Pages: [1]   Go Down
Print
Author Topic: Going to another class when clicking text?  (Read 416 times)
Mads Odgaard
Newbie
*
Posts: 1


Email




« on: March 18, 2012, 11:07:53 AM »

Lets say i got a UILabel. And when i click that i want to go to other UIViewController?

How would i do that?
Logged
fujilla
Global Moderator
Sr. Member
*****
Posts: 270


WWW




« Reply #1 on: March 19, 2012, 12:00:40 PM »

Firstly, I personally do not know how to make a UILabel accepts touch events, as I would use a UIButton and set its "Type" to "custom" (if you did not want a border/background), as that's what a UIButtons purpose is, whereas a label is simply for displaying text.

Then to get a UIButton to display another UIViewController - if you are using IB:
With your NIB file displayed, alt-click on the header file for the class to show it alongside the NIB file
Control-drag from the UIButton to the method section of the header file which will open a popup window
Change the connection to Action and give the method a name
Now go the this new method in your implementation file for the class and do something like:
Code: (Objective-C)
ViewController *viewController = [[ViewController alloc] init];
UINavigationController *navController = [[UINavigationController alloc] viewController];
[self presentModalViewController:navController animated:YES];
changing ViewController/viewController to whatever the view controller you want to show is called.
This code will present display the view controller modally, so you may need to change this depending on how you wish to display it.

I hope this helps,
Nick
http://myfirstiphoneapp.co.uk
http://easyintervalsapp.co.uk
Logged
Pages: [1]   Go Up
Print
Jump to:  



Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Entire forum contents (c) 2009 classroomM.com. All rights reserved.