Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 09-10-2011, 12:32 PM   #1 (permalink)
Registered Member
 
Join Date: Aug 2011
Posts: 9
skot is on a distinguished road
Default get the current UIViewController?

How can I get a reference to the current UIViewController? Is it possible? I tried

[[UIApplication sharedApplication] keyWindow] rootViewController]

but this value is nil.
skot is offline   Reply With Quote
Old 09-10-2011, 07:29 PM   #2 (permalink)
Senior Member
iPhone Dev SDK Supporter
 
Join Date: Aug 2008
Location: Memphis, TN, USA
Age: 24
Posts: 3,983
smithdale87 is on a distinguished road
Send a message via AIM to smithdale87
Default

Where are you trying to access this in your code? It could be as simple as "self". I don't know without more specifics.
smithdale87 is offline   Reply With Quote
Old 09-12-2011, 10:40 AM   #3 (permalink)
Registered Member
 
Join Date: Aug 2011
Posts: 9
skot is on a distinguished road
Default

I have a network operation running in the background that might need to trigger a modal view, depending on the response from the server.

This network operation can be started at several different points in the app and can't always know ahead of time which UIViewController will be active when the server response comes back.


Anyway, I came up with a solution for my purposes. It turns out that you don't need to be the *top* UIVewController in order to show a modal view. Apparently, any controller in the hierarchy can do it.

Also, it turned out it was my own fault that [[[UIApplication sharedApplication] keyWindow] rootViewController] was returning a nil value. Typically in the application:didFinishLaunchingWithOptions: method of the UIApplicationDelegate there's a line like this

Code:
  self.window.rootViewController = self.viewController;
For some reason I can no longer remember, I had changed this to something like

Code:
  [self.window addSubview:self.viewController.view];
When I changed this back to standard practice, I was able to present a modal view from any object with

Code:
   [[[[UIApplication sharedApplication] keyWindow] rootViewController] presentModalViewController:controller animated:YES];
skot is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 408
9 members and 399 guests
apatsufas, Eclectic, fiftysixty, JackReidy, teebee74, tim0504, UMAD, yomo710, yuncarl28
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,672
Threads: 94,121
Posts: 402,904
Top Poster: BrianSlick (7,990)
Welcome to our newest member, yuncarl28
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 05:01 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0