English 中文(简体)
IDView或UIScroll 观点没有更新在方案建立的控制方面的显示
原标题:UIView or UIScrollView doesn t refresh the display on programmatically created controls

I m creating melodramatically some controls, and they don t appear, it needs some kind of a refresh method.. here s my layout:
enter image description here

it s a chat, and all those messages I m creating them dynamically as the event appears, what I m creating at startup, it does appear, but what I m creating afterward fails to show, even if the code is ok,

这里,我如何建立控制(通过称为以下职能):

- (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;
        backimage=@"green_bubble.png";
    }
    else {
        left=5;
        left_hour_button=240;
        backimage=@"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》内的一个物体,从中得出。

我也想向下 bottom,每当我增加一个新信息时,我就将.。

I ve seen this post but either it doesn t work, or it acts weird on the simulator... haven t tried it on a device because I don t own an iPhone yet.

it scrolls too much or at all, but if I go to another tab, then switch back, the scroll is scrolled at the bottom, and it even shows the controls I ve created programmatically... Weird isn t it?

最佳回答

采用<代码>[自.view setNeedsDisplay],如果自称是观点控制者,或只是。 观点:

问题回答

暂无回答




相关问题
how to detect Android ListView Scrolling stopped?

I m trying to do something after scrolling stopped.So, I tried using OnScrollListener#onScrollStateChanged(SCROLL_STATE_IDLE) to detect when the scrolling stopped(either TOUCH_SCROLL or FLING)(at 1.5 ...

jQuery - ScrollTo and Serial Scroll not working together

I have tested the scrollTo() plugin, but I need a way to stop the scrolling animation, so I am looking at serialScroll(). Here is what I used with scrollTo: $( #scroller ).scrollTo( 1000px , 3000); ...

Scrolling to the bottom of a div

As part of an ajax chat room (using prototype framework) I am working on I scroll the user to the bottom each time a message is added using the below js. However if the user has scrolled up and the ...

Displaying news with javascript

I keep coming up against this issue. Displaying news on a website. And I d like to come up with a solution to use like a template, something I can just drop on a site easily. The solution I keep ...

UITextview content moves up when textview is selected

I am pretty new to this iPhone dev thing but so far I have built a pretty good app but I have stumbled into this problem that for the life of me I cannot seem to solve. Basically the app is a chat ...