IPhone - UITableView reloadData +返回第一个结果

时间:2011-08-01 17:57:33

标签: iphone uitableview

有没有办法让UITableView使用reloadData显示结果的开头,而不是显示与调用之前相同的位置?

代码:

-(void)orderResult{
    FMDatabase *db = [DatabaseManager openDatabase:@QRDATABASE];
    NSString *queryCounter = [NSString stringWithFormat:@"select count(*) as count from %@", self.appDelegate.query];
    FMResultSet *rsCount = [db executeQuery:queryCounter];
    [rsCount next];
    self.rowCounter = [rsCount intForColumn:@"count"];

    if (([rule isEqualToString:@""] )|| (rule == nil)) {
        rule = @"dist";
    }

    NSLog(@"initWithStyle: self.rowCounter = %i", self.rowCounter);

    FMResultSet *rs = [db executeQuery:queryTest];

    results = [[NSMutableArray alloc]init];

    while ([rs next]){
        NSMutableArray *aRS = [[NSMutableArray alloc] init];
        [aRS addObject:[rs stringForColumn:@"nome"]];

        [aRS addObject:[rs stringForColumn:@"dist"]];
        NSLog(@" while ([rs next]): %@ - %@",[aRS objectAtIndex:0], [aRS objectAtIndex:1]);

        [results addObject:aRS];
        [aRS release];
    }
    [db release];

}


-(IBAction)azOrg{
    NSLog(@"azOrg");
    rule = @"nome";
    [self orderResult];    
    [table reloadData];    
}

问候!

2 个答案:

答案 0 :(得分:1)

您不能使用realodData,但您可以立即使用scrollToRowAtIndexPath:atScrollPosition:animated:

-(IBAction)azOrg{
    NSLog(@"azOrg");
    rule = @"nome";
    [self orderResult];
    [table reloadData];
    [table scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]
                 atScrollPosition:UITableViewScrollPositionTop
                         animated:YES]; //Change to NO if you do not want it to animate
}

答案 1 :(得分:1)

你知道sdk文档,对吧?

查看UITableView的 - (void)scrollToRowAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UITableViewScrollPosition)scrollPosition animated:(BOOL)animated method。