您的位置:首页 > 产品设计 > UI/UE

iOS开发UI篇—使用UItableview完成一个简单的QQ好友列表(一)

2014-11-12 17:01 1021 查看
iOS开发UI篇—使用UItableview完成一个简单的QQ好友列表(一)

一、项目结构和plist文件

[b]

//
//  YYViewController.m
//  02-QQ好友列表(基本数据的加载)
//
//  Created by apple on 14-5-31.
//  Copyright (c) 2014年 itcase. All rights reserved.
//

#import "YYViewController.h"
#import "YYQQGroupModel.h"
#import "YYfriendCell.h"
#import "YYFriendsModel.h"

@interface YYViewController ()
/**
*  用来保存所有的分组数据
*/
@property(nonatomic,strong)NSArray *groupFriends;
@end

@implementation YYViewController
#pragma mark-懒加载
//1.先拿到数据,实现懒加载
-(NSArray *)groupFriends
{
if (_groupFriends==nil) {
NSString *fullpath=[[NSBundle mainBundle]pathForResource:@"friends.plist" ofType:nil];
NSArray *arrayM=[NSArray arrayWithContentsOfFile:fullpath];

NSMutableArray *models=[NSMutableArray arrayWithCapacity:arrayM.count];
for (NSDictionary *dict in arrayM) {
YYQQGroupModel *group=[YYQQGroupModel qqGroupModelWithDict:dict];
[models addObject:group];
}
_groupFriends=[models copy];
}
return _groupFriends;
}

- (void)viewDidLoad
{
[super viewDidLoad];
self.tableView.sectionHeaderHeight = 100;
}

#pragma mark-  设置数据源
//返回多少组
//为什么这里不会智能提示?因为这些方法是uitableview协议里的,默认并没有遵守协议,让主控制器类继承uitableviewcontroller后,就已经遵守了
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return self.groupFriends.count;
}
//每组返回多少行
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
//取出对应的组模型
YYQQGroupModel *group=self.groupFriends[section];
//返回对应组中的好友数
return group.friends.count;
}
//每组每行的内容
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//1.创建cell
YYfriendCell *cell=[YYfriendCell cellWithTableview:tableView];

//2.设置cell
YYQQGroupModel *group=self.groupFriends[indexPath.section];
YYFriendsModel *friends=group.friends[indexPath.row];
cell.friends=friends;
//3.返回一个cell
return cell;
}

#pragma mark - 代理方法
// 当一个分组标题进入视野的时候就会调用该方法
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
//    1.创建头部视图
UIView *view = [[UIView alloc] init];
view.backgroundColor = [UIColor grayColor];
//    2.返回头部视图
return view;
}

//设置分组头部标题的高度
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 44;
}

#pragma mark  隐藏状态栏
-(BOOL)prefersStatusBarHidden
{
return YES;
}
@end


View Code
实现的简陋效果:



三、注意点

(1)设置头部视图的方法



(2)在重写set方法时,应该考虑到回滚。

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐