我在uiviewcontroller的view中加入了一个uitableview用于显示数据,是异步加载的形式,数据从web服务器接口获得。就是代码里的userlistview,就是为什么这里必须要设置self.userListView.frame=self.view.bounds;这样一句代码,userListView 的delegate和datasource对应的协议方法才会被调用呢? 而且就算是 设置self.userList.frame=CGRectMake(<#CGFloat x#>, <#CGFloat y#>, <#CGFloat width#>, <#CGFloat height#>)这样都不行,必须要用上面那一句。 还有就是我自定义uitableviewcell中需要显示图片,我想问下这种需要大量显示图片的情况是怎样处理的呢? 因为我的程序加载tableview的时候会感觉卡卡的。还有就是我的tableview在向上拉时始终拖动不到view的最后一个cell,向上拉一截,一松手又退下去了,不知道这种现象时怎么回事? 麻烦懂的帮忙解答一下,感激不尽。我把程序压锁了发到百度网盘里的,http://pan.baidu.com/s/1i3BlEPf
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.userListView.frame=self.view.bounds;
self.userListView.delegate=self;
self.userListView.dataSource=self;
self.pageIndex=0;
self.pageSize=20;
self.length=5;
self.isloadling=NO;
self.currcount=0;
self.userList=[[[NSMutableArray alloc] init] autorelease];
self.title=@"我的联系人";
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.refreshView=[[EGORefreshTableHeaderView alloc] initWithFrame:
CGRectMake(0,480, 320, 480)];
self.refreshView.delegate=self;
[self.view addSubview:self.refreshView];
if([self.userList count]==0)
{
self.userListView.hidden=YES;
self.loadingView.hidden=NO;
[self getUserList:self.pageSize pageIndex:self.pageIndex];
self.isloadling=YES;
self.refreshView.hidden=YES;
}
// Do any additional setup after loading the view from its nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(NSMutableArray *) getUserList:(NSInteger)pageSize pageIndex:(NSInteger)pageIndex
{
[NSThread detachNewThreadSelector:@selector(doGetUserList) toTarget:self withObject:nil];
return nil;
}
-(void) doGetUserList
{
SNSUserOper *oper=[[SNSUserOper alloc] init];
NSMutableArray * array=[oper getSnsUserListOfEno];
[self.userList addObjectsFromArray:array];
[oper release];
dispatch_sync(dispatch_get_main_queue(),^(void){
[self appendUserListToTable:self.userList];
//[userListView reloadData];
});
}
-(BOOL) appendUserListToTable:(NSMutableArray *)userList
{
self.userListView.hidden=NO;
self.loadingView.hidden=YES;
self.refreshView.hidden=NO;
self.pageIndex++;
[userListView reloadData];
return YES;
// NSMutableArray *indexpaths=[[[NSMutableArray alloc] init] autorelease];
//
// for(NSUInteger i=0;i<self.length;i++)< p="">
// {
// if(self.currcount+i< self.userList.count-1)
// {
// [indexpaths addObject:[NSIndexPath indexPathForRow:self.currcount+i inSection:0]];
// }
// }
// @try {
// self.pageIndex++;
// [self.userListView beginUpdates];
// [self.userListView insertRowsAtIndexPaths:indexpaths withRowAnimation:UITableViewRowAnimationFade];
// [self.userListView endUpdates];
// }
// @catch (NSException *exception) {
// NSLog(@"log:%@",exception.description);
// }
// return YES;
}
-(BOOL) isShowUserTableCellBnt:(UserBntType) oneBntType{
return false;
}
-(void) attenBntTuched:(MyUITableViewCell *) sender{
}
-(void) conmunicateBntTuched:(MyUITableViewCell *) sender{
}
-(void) homePageBntTuched:(MyUITableViewCell *) sender{
}
- (void)egoRefreshTableHeaderDidTriggerRefresh:(EGORefreshTableHeaderView*)view
{
[self getUserList:self.pageSize pageIndex:self.pageIndex];
}
- (BOOL)egoRefreshTableHeaderDataSourceIsLoading:(EGORefreshTableHeaderView*)view
{
return self.isloadling;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 4;
return self.pageIndex*self.length;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 71;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString * identifer=@"mainusercell";
MyUITableViewCell * cell=[tableView dequeueReusableCellWithIdentifier:identifer];
if(cell==nil){
@try {
SNSUser * user=(SNSUser *)[self.userList objectAtIndex:[indexPath row]];
cell=[[[NSBundle mainBundle] loadNibNamed:@"MyUITableViewCell" owner:self options:nil] lastObject];
cell.userName.text=user.nick_name;
cell.userSex.text=@"女";
cell.userSign.text=user.eshortname;
NSString * headpath=[SNSCommonOper getDocPath:user.photo_path_small];
cell.headImage=[[UIImageView alloc] initWithImage:[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:headpath]]]];
self.currcount++;
}
@catch (NSException *exception) {
NSLog(@"log:%@",exception.description);
}
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//跳转到人员详细页面
//MyUserDetailViewController *detail=[[[MyUserDetailViewController alloc] initWithNibName:MyUserDetailViewController bundle:nil]];
}
- (void)dealloc
{
self.userList=nil;
[super dealloc];
}
@end