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 08-08-2010, 02:36 AM   #1 (permalink)
Registered Member
 
Join Date: Jul 2010
Posts: 142
sleaver is on a distinguished road
Default Views not updating when wanted

I'm working on an RSS reader and I want to show a transparent modal view while the feed is updating before the next view containing all the feed items and here is the code:

PHP Code:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
// Load the transparent loading modal view
    
loadingView = [LoadingView loadingViewInView:[self.view.window.subviews objectAtIndex:0]];
    
    
// Navigation logic may go here. Create and push another view controller.
    
FeedInfo *feed = (FeedInfo *)[eventsArray objectAtIndex:indexPath.row];    
    [
self showFeed:feed animated:YES];
    [
feed release];

PHP Code:
- (void)showFeed:(FeedInfo *)feed animated:(BOOL)animated {
    
// Create a detail view controller, set the recipe, then push it.
    
FeedDetailListTableViewController *feedDetailViewController = [[FeedDetailListTableViewController allocinitWithNibName:@"FeedDetailListTableView" bundle:nil];
    
feedDetailViewController.feed feed;
    
    
// Get feed items
    
[UIApplication sharedApplication].networkActivityIndicatorVisible YES;
    
FeedHandler *fh = [[FeedHandler allocinit];
    
fh.feed feed;
    [
fh RefreshFeed:feed.link];
    [
fh release];
    
    
// Remove the loading view
    
[loadingView performSelector:@selector(removeViewwithObject:nil];
    
    
// Display view controller
    
[self.navigationController pushViewController:feedDetailViewController animated:animated];
    [
feedDetailViewController release];

The problem is that the loadingView does not display until the feedDetailViewController is pushed. I know this because if I comment out the line removing the window it will display as soon as the feedDetailViewController view is pushed. The loadingView doesn't need pushing as it's not done in the example I got this from and it wouldn't show when the remove line is commented out.

I have also ran into this problem with my custom UITableViewCell, I can add/change/remove items in the cell
PHP Code:
if (selected) { } 
using

PHP Code:
- (void)setSelected:(BOOL)selected animated:(BOOL)animated 
But the changes can't be seen until the next view controller is pushed on to the UINavigationController. You can imaging they pretty much disappear as soon as they are shown.

So, do you know why this may be happening? If so I would appreciate any ideas on how this can be solved!

Thanks
sleaver is offline   Reply With Quote
Old 08-08-2010, 08:27 AM   #2 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by sleaver View Post
I'm working on an RSS reader and I want to show a transparent modal view while the feed is updating before the next view containing all the feed items.
<snip>
The problem is that the loadingView does not display until the feedDetailViewController is pushed. I know this because if I comment out the line removing the window it will display as soon as the feedDetailViewController view is pushed. The loadingView doesn't need pushing as it's not done in the example I got this from and it wouldn't show when the remove line is commented out.

I have also ran into this problem with my custom UITableViewCell, I can add/change/remove items in the cell
PHP Code:
if (selected) { } 
using

PHP Code:
- (void)setSelected:(BOOL)selected animated:(BOOL)animated 
But the changes can't be seen until the next view controller is pushed on to the UINavigationController. You can imaging they pretty much disappear as soon as they are shown.

So, do you know why this may be happening? If so I would appreciate any ideas on how this can be solved!

Thanks
I don't completely follow your sample code, but bet I know what the issue is anyway.

In iOS (and Mac OS) UI changes don't take place until you revisit the event loop. If you add a view, change a highlight flag, or whatever, you have to return from your method and let the system trigger a draw event before you see the results on the screen.

If you do a bunch of stuff, then push a view controller, THEN return, you won't get a chance to see the changes, because you haven't returned until after you push the view controller.

If you need the UI to update, you can use a method

performSelector:withObject:afterDelay:

You might do something like this:


//set a table view cell to selected (or whatever UI change)
[self performSelector: pushNewView withObject: nil afterDelay: 0];


You would then write a function pushNewView that actually pushed the new view controller. That method would get called after the system re-visited the main event loop and handled the drawing you requested.

performSelector:withObject:afterDelay: allows the system to return to the main event loop even if the delay value is zero.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 08-08-2010, 12:59 PM   #3 (permalink)
Registered Member
 
Join Date: Jul 2010
Posts: 142
sleaver is on a distinguished road
Default

Quote:
Originally Posted by Duncan C View Post
I don't completely follow your sample code, but bet I know what the issue is anyway.

In iOS (and Mac OS) UI changes don't take place until you revisit the event loop. If you add a view, change a highlight flag, or whatever, you have to return from your method and let the system trigger a draw event before you see the results on the screen.

If you do a bunch of stuff, then push a view controller, THEN return, you won't get a chance to see the changes, because you haven't returned until after you push the view controller.

If you need the UI to update, you can use a method

performSelector:withObject:afterDelay:

You might do something like this:


//set a table view cell to selected (or whatever UI change)
[self performSelector: pushNewView withObject: nil afterDelay: 0];


You would then write a function pushNewView that actually pushed the new view controller. That method would get called after the system re-visited the main event loop and handled the drawing you requested.

performSelector:withObject:afterDelay: allows the system to return to the main event loop even if the delay value is zero.
Thanks for the reply.

After more researching that is pretty much the same conclusion I came too but I went the route of NSThread. Is that the right way or should I just use a plain function?

Probably a dumb question but why does a delay of 0 all the eventLoop revisit?
sleaver is offline   Reply With Quote
Old 08-08-2010, 02:45 PM   #4 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by sleaver View Post
Thanks for the reply.

After more researching that is pretty much the same conclusion I came too but I went the route of NSThread. Is that the right way or should I just use a plain function?

Probably a dumb question but why does a delay of 0 all the eventLoop revisit?
NSThreads will work too, but NSOperationQueues are easier to use.

The performSelector:withObject:afterDelay queues up a request to do a performSelector call later. The call doesn't get queued until the next pass through the event loop, even if the delay is zero.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C 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: 308
8 members and 300 guests
arash5500, HemiMG, linkmx, mediaspree, Objective Zero, Paul Slocum, stanny, Touchmint
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,655
Threads: 94,116
Posts: 402,889
Top Poster: BrianSlick (7,990)
Welcome to our newest member, pungs
Powered by vBadvanced CMPS v3.1.0

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