当前位置: 代码迷 >> Iphone >> UITableView 页面刷新解决办法
  详细解决方案

UITableView 页面刷新解决办法

热度:438   发布时间:2016-04-25 06:15:45.0
UITableView 页面刷新
我写了一个UITableView分页,现在分页是成功了,我也在新的数据回来后,我使用了reloadData刷新界面,但是,数据是刷新了但是页面的显示没有刷新,例如,第一页加载显示,没有问题,然后点击加载更多。。。请求了第二页的数据,数据是刷新了,但是界面没有刷新,什么意思呢,就是,第二页数据回来以后,第二页的第一条数据加载到了那个加载更多那块。。。但是加载更多还在显示着,本来应该显示第二页第一条数据的标题!我直接上代码




C/C++ code
////  LtsqViewController.m//  TianWei////  Created by newuser on 12-5-10.//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.//#import "LtsqViewController.h"#import "AsyncImageView.h"#import "FirstDetailViewController.h"#import "WebService.h"#import "Data.h"@interface LtsqViewController ()@end@implementation LtsqViewController-(void)viewWillAppear:(BOOL)animated{       // self.navigationController.navigationBar.hidden=YES;}- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];    if (self) {        // Custom initialization    }    return self;}- (void)viewDidLoad{    self.navigationItem.title=@"论坛社区";    self.view.backgroundColor= [UIColor whiteColor];        gjxwArray = [[NSMutableArray alloc]initWithCapacity:0];        loading = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];    loading.frame = CGRectMake(150, 170, 20, 20);    //    listViewLoading.hidesWhenStopped = YES;    loading.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray;    [self.view addSubview:loading];    [loading release];    [loading startAnimating];        //底部数据加载    homeTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 320, 354)];    [homeTableView setDelegate:self];    [homeTableView setDataSource:self];    [self.view addSubview:homeTableView];    [homeTableView release];        page = 1;    NSString *urlParm = [NSString stringWithFormat:@"news=%@&command=%@&page=%i",@"new2",@"2",page];    [[WebService instance]doHttpRequest:@"http://192.168.131.73:8080/TianWei/data.do" :urlParm];    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(update:) name:@"newsUpdate" object:nil];                [super viewDidLoad];    // Do any additional setup after loading the view.}-(void)update:(NSNotification*)notification{    [[NSNotificationCenter defaultCenter] removeObserver:self name:notification.name object:nil];    Data *data =[notification object];        if([data.listArray count]>0){        [gjxwArray removeLastObject];    }        for (NSDictionary *dic in data.listArray) {        List *list = [[List alloc]init];        [list setOid:[[dic valueForKey:@"id"] intValue]];        [list setTime:[dic valueForKey:@"time"]];        [list setTitle:[dic valueForKey:@"title"]];        [list setImage:[dic valueForKey:@"image"]];        [list setUrl:[dic valueForKey:@"url"]];        [gjxwArray addObject:list];        [list release];    }    if([data.listArray count]>= 10){        List *l = [[List alloc]init];        [l setTitle:@"more"];        [gjxwArray addObject:l];        [l release];    }        [homeTableView reloadData];}//选中Cell响应事件-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{     List *list =[gjxwArray objectAtIndex:indexPath.row];    if([list.title isEqualToString:@"more"]){        page=page+1;        NSString *urlParm = [NSString stringWithFormat:@"news=%@&command=%@&page=%i",@"new2",@"2",page];        [[WebService instance]doHttpRequest:@"http://server.bcjsw.com:8889/TianWei/data.do" :urlParm];        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(update:) name:@"newsUpdate" object:nil];    }else{               FirstDetailViewController *firstDettaiView = [[[FirstDetailViewController alloc]init]autorelease];        firstDettaiView.oid = list.oid;        firstDettaiView.titleText = list.title;        firstDettaiView.url = list.url;        [self.navigationController pushViewController:firstDettaiView animated:YES];    }}//返回行数-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{    return  [gjxwArray count];    }//返回View count-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{    return 1;}//组装每一条的数据-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{    NSString *CellIdentifier =[NSString stringWithFormat:@"Cell%d",indexPath.row];    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];        if(cell==nil){                cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]autorelease];        List *kainlist = [gjxwArray objectAtIndex:indexPath.row];        NSLog(@"--------=--title---->%@",kainlist.title);        if([[kainlist title] isEqualToString:@"more"]) {             cell.textLabel.text = @"加载更多...";        }else{            List *list = [gjxwArray objectAtIndex:indexPath.row];            AsyncImageView *downImage = [[AsyncImageView alloc]initWithFrame:CGRectMake(10, 3, 50, 40)];            downImage.image= [UIImage imageNamed:@"tianweiForum.jpg"];            [downImage setImgUrl:list.image];            [cell addSubview:downImage];            [downImage release];                        UILabel *title  =[[UILabel alloc]initWithFrame:CGRectMake(80, 12, 203, 20)];            title.font = [UIFont systemFontOfSize:16.0f];            title.text = list.title;            [cell addSubview:title];            [title release];        }            }                cell.selectionStyle=UITableViewCellSelectionStyleNone;    return cell;        }- (void)viewDidUnload{    [super viewDidUnload];    // Release any retained subviews of the main view.}- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{    return (interfaceOrientation == UIInterfaceOrientationPortrait);}@end
  相关解决方案