开发者

subview not showing on already displayed view

I'm new on iPhone development and I'm stuck with a subview not showing after the controller is notified to refresh these items.

So, it's my main page showing, showing the 3-last items of a newsfeed at the bottom. The view controler handles the loading of the newsfeed (in a NSArray). When loading the page, the newsfeed is correctly displayed as a subview of the main view. However, when the view already exists (for example just after login for the first time), the newsfeed is not displayed, or refresehed. The avatar images that are fetched from internet asynchronously are displayed correctly. But not the labels.

The debug shows that the code is correctly executed...but nothing happens...

Here is the code handling the notification and refresh.

I'm sure I miss something stupid but cannot put my finger on it. Does an UILabel or UIImage of the subview can avoid the element to be refreshed?

Thanks for the help!

The controler code

-(void) handleRefreshNewsfeed:(NSNotification*)notification{

if (self.newsfeedMostRecentDate == nil){
    NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyyMMdd HH:mm"];
    self.newsfeedMostRecentDate = [dateFormatter dateFromString:@"20100101 00:00"];
    [dateFormatter release];
}
NSArray * newsfeed = [cdw getNewsfeedForUser:self.currentUser andLimit:self.newsfeedLimit];
if ([newsfeed count] > 0){
    self.newsfeedMostRecentDate = [(Newsfeed *)[newsfeed objectAtIndex:0] posted];
    if ([self.view isKindOfClass:[MenuView class]]){
        [(MenuView *)self.view refreshNewsfeed:newsfeed];
    }
}

}

The main view declaration:

@interface MenuView : UIView {
MenuNewsfeed                * newsFeedView;  
}
@property(nonatomic, retain) IBOutlet MenuNewsfeed *newsFeedView;

-(void)displayNewsfeed:(NSArray *)newsfeed;
-(void)refreshNewsfeed:(NSArray *)newsfeed;

The main view code :

-(void)displayNewsfeed:(NSArray *)newsfeed{
[self.newsFeedView setCurrentUser:currentUser];
[self.newsFeedView displayNewsfeed:newsfeed];

[UIView animateWithDuration:0.75f
    delay: 0.0
        options: UIViewAnimationOptionCurveEaseIn
     animations:^{
         self.newsFeedView.开发者_JS百科alpha = 1.0;
     }
     completion:^(BOOL finished){
         //nothing
     }
 ];
}

-(void)refreshNewsfeed:(NSArray *)newsfeed{

if ([self.newsFeedView.newsfeed count] > 0){
    [UIView animateWithDuration:0.50f
         delay: 0.0
            options: UIViewAnimationOptionCurveEaseIn
         animations:^{
             self.newsFeedView.alpha = 0.0;
         }
         completion:^(BOOL finished){
            // [self displayNewsfeed:newsfeed];
         }
     ]; 
}else {

    [self displayNewsfeed:newsfeed];
}
}

Michael


This may not answer your problem.

However, there is a small glitch that I can see. The CGRectMake (50, 100, 55, 12) will create a rect of 12px wight but 55px height.

Well, at least "te" or "tes" of your text should be visible as I do not see any insects. With some insect value (10 or so) it could happen that noting of your text string is visible.

Or no. When a text is clipped, depending on the default line break mode, it could be truncated to a certain extend and some "..." added at the end. Could it be that you only see some points instead of "test test test"?

Otherwise check wether the tmp label is hidden by some other view, although it should be most on top of the view's stack.

But give it some realistic rect of maybe 20, 100, just to be save, before you do any further testing.


I've found out what the problem was : the code handling the notification (and modifying the UI) was not processed on the main thread.

[self performSelectorOnMainThread:@selector(refreshNewsfeed) withObject:notification.object waitUntilDone:NO];

Calling the refresh method via performSelectorOnMainThread solved the issue.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜