uitableview上提刷新数据

来源:互联网 发布:检测显卡的软件 编辑:程序博客网 时间:2024/05/17 02:12
// Override to allow orientations other than the default portrait orientation.- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {    // Return YES for supported orientations    //return (interfaceOrientation == UIInterfaceOrientationPortrait);returnNO;}#pragma mark 刷新- (void)refresh:(id)sender{    //刷新的时候初始化分页    self.currentPage = 1;    //刷新返回顶部    if (self.list.count>0) {        NSIndexPath *indexPath = [NSIndexPathindexPathForRow:0inSection:0];        [self.tableViewscrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionMiddleanimated:NO];    }    [NSThreaddetachNewThreadSelector:@selector(didStartRequest) toTarget:selfwithObject:nil];}#pragma mark 下载数据//本地模拟,不走网络数据请求了- (void)didStartRequest{    NSAutoreleasePool *pool = [[NSAutoreleasePoolalloc] init];if (self.currentPage==1) {[self.listremoveAllObjects];}    if (self.list.count) {        [self.listremoveLastObject];    }for (int i=(self.currentPage-1)*self.pageSize;i<self.currentPage*self.pageSize;i++) {NSString *string = [NSStringstringWithFormat:@"第%d行",i+1];[self.listaddObject:string];        //分页总有一个尽头的,所以在这里我就强制结束了        if (i==listLength) {            break;        }}    //根据不同的分页算法,改变下面的代码    if (self.list.count>=self.pageSize && self.list.count%self.pageSize==0) {        [self.listaddObject:@"正在加载更多"];    }else{        [self.listremoveLastObject];    }    [selfperformSelectorOnMainThread:@selector(didFinishRequest) withObject:nilwaitUntilDone:NO];    [pool release];}- (void)didFinishRequest{[self.tableViewreloadData];}