我有以下的應用程序,這是想聊天,所以我編程創建一些標籤,圖像和按鈕。
問題是,我在啓動時添加的那個顯示,而我之後添加的那個不顯示。
這就像視圖需要清爽或什麼。 如果我把從設定到按鈕的IBAction爲相同的繪圖功能......它顯示的內容.. 如果它來自於尋找新的活動,並通過通知類線程事件:編程方式創建的標籤和圖像不顯示在屏幕上
[[NSNotificationCenter defaultCenter] postNotificationName:@"NewMessageNotification" object:self userInfo:values];
它然後不顯示任何東西。 但是這個函數實際上被調用了(我用調試器進行了檢查)它是不是使用視圖的正確實例?
這裏是我的佈局:
,這裏是我的函數創建該控件:
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];
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];
我也想給UIScrollView的自動滾動到下的時候我把這個功能..但它失敗了,這就像模擬器快要瘋了,當我撥打以下: 我嘗試使用
CGPoint offset = CGPointMake(0,lastcalculatedHeight);
[scrollView setContentOffset: offset animated: YES];
我得到這個從 UIScrollView scroll to bottom programmatically
另外,你在哪裏計算calculatedHeight和lastcalculatedHeight? – 2011-03-23 17:55:30
是的,我正在這樣做,它全部顯示在屏幕上,如果我從一個按鈕的事件調用函數觸摸它的內部更新,我可以看到它的廣告,...如果我通過NSNotificationCenter做它它doesn沒有工作......它調用的功能,但它不會發布任何可見的更新... – PartySoft 2011-03-23 21:03:34