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