我写了一个UITableView分页,现在分页是成功了,我也在新的数据回来后,我使用了reloadData刷新界面,但是,数据是刷新了但是页面的显示没有刷新,例如,第一页加载显示,没有问题,然后点击加载更多请求了第二页的数据,数据是刷新了,但是界面没有刷新,什么意思呢,就是,第二页数据回来以后,第二页的第一条数据加载到了那个加载更多那块但是加载更多还在显示着,本来应该显示第二页第一条数据的标题!我直接上代码
//
// 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
//
// 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
解决方案 »
- NSHomeDirectory()为什么返回的目录是/var/....
- objective-c 中一个类的列表类型怎么定义
- 教个问题!关于多个label的显示问题(也可以说是动画效果?)
- 苹果TS流打包过程的一些问题
- ios系统网站开发?
- mouseEntered什么时候触发执行
- xcode6 如何制作ipa越狱包?
- 上传到AppStore出现问题
- 咨询一下技术问题,关于RED5和音频广播系统和IOS谁有案例发几个给我吧
- 别看人家效率高,其实是他学会了“偷懒“。刚开发了个小工具分享一下!!
- 救命!如何改变xcode4中的开发者账号?
- @@objective c arc was enabled in pch file but is currently disabled@@
//组装每一条的数据
-(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;
}
改成
//组装每一条的数据
-(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;
}
你把这句NSString *CellIdentifier =[NSString stringWithFormat:@"Cell%d",indexPath.row];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];改成NSString *CellIdentifier =@"CellIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];试试。
你可以在网上找找UITableViewCell复用原理的文章看看,或者看看这个