0

我正在尝试在此代码中刷新我的主视图。它显示了正确的子视图,但它保留了已经显示的其他视图。我已经尝试过 setNeedsDisplay 和 setNeedsLayout 但没有成功。

有任何想法吗?

代码:

-(void)setViewsForLecture:(NSString *)date{
       int scrollHeight = 0;

       [self.view setNeedsDisplay];
       FMDatabase* db = [DatabaseManager openDatabase];
       NSString *query = [NSString stringWithFormat:@"select *  from tbl_lectures where day like \"%%%@%%\" ", date];

       FMResultSet *rs= [db executeQuery:query];

       //Counts how many lectures
       int position = 0;

       while ([rs next]) { 
          NSMutableArray *speakers = [[NSMutableArray alloc] initWithCapacity:30];

           NSString *lectureName = [rs stringForColumn:@"lecturename"];

           FMResultSet *speakersList = [db executeQuery:@SELECT_SPEAKER_FOR_LECTURE, lectureName];

           while ([speakersList next]) {
               [speakers addObject:[speakersList stringForColumn:@"speaker"] ];
           }

           if ([speakers count] % 2 == 0)
           {
               scrollHeight += [speakers count]*40;
           }
           else
           {
               scrollHeight += (1 + ([speakers count] -1)/2)*40;
           }
           NSLog(@"Csantos: speakers for %@: %i",lectureName, [speakers count]);
           UIView *aLecture = [CustomInterface viewForLecture:[rs stringForColumn:@"lecturename"]
                                            onPosition:position
                                          withSpeakers:speakers];



           [self.scroll addSubview:aLecture];

           [aLecture release];
           [speakers release];
           scrollHeight += 280;
           position++;
       }

       self.scroll.contentSize = CGSizeMake(300, scrollHeight);
       [db release];
   }

问候!

4

2 回答 2

0

我让它工作了!

我想我不明白 setNeedsDisplay 是如何工作的。在这种情况下,是否也应该重绘我的 ScrollView?

无论如何,这是现在可以使用的代码:

-(IBAction)clickOnDate1{
    for (UIView *view in [self.scroll subviews]) {
        [view removeFromSuperview];
    }
    NSLog(@"Date1 clicked");
    [self setViewsForLecture:@"4"];
}

并感谢 PengOne 的帮助!

于 2011-07-14T22:26:28.900 回答
0

试着打电话

  [self.view setNeedsDisplay];

在方法结束时,在您进行更改之后。

于 2011-07-14T21:49:08.920 回答