子视图未显示在已显示的视图上

发布于 2024-11-30 19:01:30 字数 2188 浏览 0 评论 0原文

我是 iPhone 开发新手,在通知控制器刷新这些项目后,我遇到了子视图未显示的问题。

所以,这是我的主页显示,在底部显示新闻源的最后 3 项。 视图控制器处理新闻源的加载(在 NSArray 中)。 加载页面时,新闻源正确显示为主视图的子视图。但是,当视图已经存在时(例如,首次登录后),新闻源不会显示或刷新。从互联网异步获取的头像图像可以正确显示。但不是标签。

调试显示代码已正确执行...但没有任何反应...

这是处理通知和刷新的代码。

我确信我错过了一些愚蠢的事情,但无法指出它。 子视图的UILabel或UIImage是否可以避免元素被刷新?

感谢您的帮助!

控制器代码

-(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];
    }
}

}

主视图声明:

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

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

主视图代码:

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

[UIView animateWithDuration:0.75f
    delay: 0.0
        options: UIViewAnimationOptionCurveEaseIn
     animations:^{
         self.newsFeedView.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

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.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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

在梵高的星空下 2024-12-07 19:01:30

这可能无法回答您的问题。

然而,我可以看到一个小故障。 CGRectMake (50, 100, 55, 12) 将创建一个宽度为 12px、高度为 55px 的矩形。

好吧,至少你的文字的“te”或“tes”应该是可见的,因为我没有看到任何昆虫。对于某些昆虫值(10 左右),可能会出现文本字符串的注释可见的情况。

或者没有。当文本被剪切时,根据默认的换行模式,它可能会被截断到一定程度,并在末尾添加一些“...”。
难道你只看到了一些点,而不是“试试试”?

否则检查 tmp 标签是否被其他视图隐藏,尽管它应该位于视图堆栈的最顶部。

但在进行任何进一步测试之前,请给它一些实际的矩形(可能是 20、100),以便保存。

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.

溺ぐ爱和你が 2024-12-07 19:01:30

我发现了问题所在:处理通知(并修改 UI)的代码未在主线程上处理。

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

通过performSelectorOnMainThread调用refresh方法解决了这个问题。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文