2011-03-23 19 views
1

我最近在另一个iPhone的问题难倒了显示。 我创建情节性的一些控制,他们不出现,它需要某种刷新方法的.. 这里是我的布局: enter image description here的UIView或UIScrollView的不刷新programaticaly创建的控件

这是一个聊天,并且所有这些消息我正在创建它们dynamicaly作为事件出现, 我创建在启动时的东西,它似乎,但什么我创建之后无法显示,即使代码是好的,

这里的我怎么创建控件(由呼叫以下功能):

- (void) AddNewMessage: (NSString *)msg date1:(NSString*) date2 { 


    NSString *backimage =[NSString stringWithString:@""]; 
    NSString *who =[NSString stringWithString:@"1"]; 

     calculatedHeight=floor(msg.length/40)*20; 
      if (calculatedHeight<30) calculatedHeight=30; 
     if ([who isEqualToString:@"1"]) { 
      left=85; 
      left_hour_button=25; 
      [email protected]"green_bubble.png"; 
     } 
     else { 
      left=5; 
      left_hour_button=240; 
      [email protected]"grey_bubble.png"; 
     } 

     UIButton *button1 = [[UIButton alloc] initWithFrame:CGRectMake(left, lastcalculatedHeight-10, 230, calculatedHeight+10)]; 
     [button1 setBackgroundImage:[[UIImage imageNamed:backimage] stretchableImageWithLeftCapWidth:9 topCapHeight:13] forState:UIControlStateDisabled]; 
     [button1 setEnabled:FALSE];   
     [scrollView addSubview:button1]; 
     [button1 release]; 



     UIButton *buttonTime = [[UIButton alloc] initWithFrame:CGRectMake(left, lastcalculatedHeight+40, 50, 20)]; 
     [buttonTime setBackgroundImage:[[UIImage imageNamed:@"hour_bubble.png"] stretchableImageWithLeftCapWidth:9 topCapHeight:13] forState:UIControlStateDisabled]; 
     [buttonTime setFrame:CGRectMake(left_hour_button, lastcalculatedHeight+calculatedHeight-30, 55, 25)]; 
     [buttonTime setTitle:date2 forState:UIControlStateDisabled];     
     [buttonTime setTitleColor:[UIColor blackColor] forState:UIControlStateDisabled]; 
     buttonTime.titleLabel.font=[UIFont fontWithName:@"Helvetica" size:8.0]; 
     buttonTime.titleLabel.lineBreakMode= UILineBreakModeWordWrap; 
     [buttonTime setEnabled:FALSE]; 
     [scrollView addSubview:buttonTime]; 
     [buttonTime release]; 


     UILabel *labelMessage = [[UILabel alloc] initWithFrame:CGRectMake(left+5, lastcalculatedHeight-5, 220, calculatedHeight)];   
     [labelMessage setText:msg]; 
     [labelMessage setFont:[UIFont fontWithName:@"Arial" size:12.0]]; 
     [labelMessage setLineBreakMode:UILineBreakModeWordWrap]; 
     [labelMessage setTextColor:[UIColor blackColor]]; 
     [labelMessage setAdjustsFontSizeToFitWidth:NO]; 
     [labelMessage setNumberOfLines:floor(msg.length/40)+2]; 
     [labelMessage setBackgroundColor:[UIColor clearColor]]; 
     [scrollView addSubview:labelMessage]; 
     [labelMessage release]; 


     lastcalculatedHeight+=calculatedHeight+20; 

     totalHeight+=calculatedHeight; 

    scrollView.contentSize = CGSizeMake(240, lastcalculatedHeight); 



} 

有人能告诉我如何“刷新”显示?

的滚动视图是从哪个类派生

我也将要向下滚动至底部滚动视图UIView的,每个我添加新的消息的时间内的对象。

我见过this post但eighter它不工作,或者它的作用在模拟器上怪异...... 还没有尝试过的设备上,因为我没有自己的iphone尚未..

它滚动太多或根本,但如果我去到另一个选项卡,然后再切换回,滚动在底部滚动,它甚至可以显示我programaticaly创建了控制...... 奇怪是不是?

回答

0

尝试使用[self.view setNeedsDisplay],如果自我是一个视图控制器,或者只是[scrollView setNeedsDisplay]

+1

我发现,问题是,我是通知功能,这是不是从主线程调用..所以我发现,通过如果有检查和回顾同样的函数调用从主线程功能相同与相同的参数..工作 – PartySoft 2011-04-12 09:04:21