I'm trying to refresh my main view in this code. It shows the right sub-view, but it's keeping the other views already shown. I already tried setNeedsDisplay and setNeedsLayout but no success.
Any ideas?
Code:
-(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];
}
Regards!
Try calling
[self.view setNeedsDisplay];
at the end of the method, after you've made the changes.
I got it working!
I think I didn't understand exactly how setNeedsDisplay works. In this case, was it supposed to redraw my ScrollView too?
Anyway, here is the code that works now:
-(IBAction)clickOnDate1{
for (UIView *view in [self.scroll subviews]) {
[view removeFromSuperview];
}
NSLog(@"Date1 clicked");
[self setViewsForLecture:@"4"];
}
and thanks PengOne for trying to help!
精彩评论