2012-01-28 19 views
0

每次這個標籤被加載而不是更新動態標籤,它會在它上面寫一個全新的標籤。我需要在代碼中添加什麼,以便更新它或清除動態標籤,然後放入新標籤。我覺得它可能只是一個簡單的一行修復。下面是代碼的簡化版本:ios正確的方式來更新與viewdidarar programatic uilabels

- (void)viewDidAppear:(BOOL)animated 
    { 
     [super viewDidAppear:YES]; 
     goalArray = [[NSMutableArray alloc] init]; 
     NSURL *url = [NSURL URLWithString:@"http://localhost/goal.php"]; 
     ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url]; 
     [request setPostValue:test forKey:@"name"]; 
     [request setDelegate:self]; 
     [request startAsynchronous];   
    } 
    - (void)requestFinished:(ASIFormDataRequest *)request 
    { 
     ... 
      for (id myArrayElement in goalArray) 
      { 
       NSLog(@"y value:%i", yValue); 
       UILabel *label = [[UILabel alloc] initWithFrame: CGRectMake(0, yValue, 80, 44)]; 
       label.font = [UIFont systemFontOfSize:12]; 
       label.textColor = [UIColor blackColor]; 
       label.backgroundColor = [UIColor clearColor]; 
       label.text = myArrayElement; 
       [self.view addSubview:label]; 
       yValue += 44; 
      } 
     } 
+1

如果你想投票評論會很好 – user1108720 2012-01-28 01:56:59

回答

0

在requestFinished:在for循環之前,補充一點:

for (UIView *die in [self subviews]) { // clear out previous label 
    if (die.tag == 123) { 
     [die removeFromSuperview]; 
    } 
} 

,然後你for循環內,補充一點:

label.tag = 123; //doesn't have to be 123, as long as it's an int that matches the one above. 
相關問題