iphone - SetNeedsDisplay无效

时间:2011-07-14 21:45:01

标签: iphone setneedsdisplay

我正在尝试在此代码中刷新我的主视图。它显示了正确的子视图,但它保持其他视图已经显示。我已经尝试过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];
   }

问候!

2 个答案:

答案 0 :(得分:0)

尝试拨打

  [self.view setNeedsDisplay];

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

答案 1 :(得分:0)

我开始工作了!

我想我并不完全理解setNeedsDisplay是如何工作的。在这种情况下,它是否应该重绘我的ScrollView?

无论如何,这是现在有效的代码:

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

并感谢PengOne试图提供帮助!