iOS QQ列表效果实现

iOS QQ列表效果实现,第1张

概述iOS QQ列表效果实现

下面是内存溢出 jb51.cc 通过网络收集整理的代码片段。

内存溢出小编现在分享给大家,也给大家做个参考。

// controller@interface VIEwController : UIVIEwController <UItableVIEwDataSource, UItableVIEwDelegate>@property (nonatomic, retain) NSMutableArray *dataList;   // 数据@property (nonatomic, retain) UItableVIEw *tableVIEw;@end
@implementation VIEwController- (voID)vIEwDIDLoad {    [super vIEwDIDLoad];    // Do any additional setup after loading the vIEw, typically from a nib.    [self initDataList];   // 初始化数据        // 向下移20    CGRect frame = self.vIEw.frame;    frame.origin.y = 20;    frame.size.height = frame.size.height - 20;    self.tableVIEw = [[UItableVIEw alloc] initWithFrame:frame style:UItableVIEwStylePlain];        // 设置委托    self.tableVIEw.dataSource = self;    self.tableVIEw.delegate = self;    [self.vIEw addSubvIEw:self.tableVIEw];}- (voID)dIDReceiveMemoryWarning {    [super dIDReceiveMemoryWarning];    // dispose of any resources that can be recreated.}#pragma mark - DataSource实现// 一共几个section- (NSInteger)numberOfSectionsIntableVIEw:(UItableVIEw *)tableVIEw {    return [self.dataList count];}// 每个section下有多少个组- (NSInteger)tableVIEw:(UItableVIEw *)tableVIEw numberOfRowsInSection:(NSInteger)section {    List *List = [self.dataList objectAtIndex:section];    NSMutableArray *array = List.groups;    NSInteger all = [array count];    for (Group *group in array) {        if (group.isDelop) {            all = all + [group.frIEnds count];        }    }    return all;}// 显示每个cell- (UItableVIEwCell *)tableVIEw:(UItableVIEw *)tableVIEw cellForRowAtIndexPath:(NSIndexPath *)indexPath {    if ([self isGroup:indexPath]) {        return [self getGroupCell:tableVIEw and:indexPath];   // 分组的cell    }    return [self getFrIEndCell:tableVIEw and:indexPath];      // 好友cell}/* * 获得section标题 **/- (Nsstring *)tableVIEw:(UItableVIEw *)tableVIEw TitleForheaderInSection:(NSInteger)section {    List *List = [self.dataList objectAtIndex:section];    return List.Title;}#pragma mark - 点击事件// 单击的处理,若是分组 则展开,否则不处理- (voID)tableVIEw:(UItableVIEw *)tableVIEw dIDSelectRowAtIndexPath:(NSIndexPath *)indexPath {    Group *group = [self isGroup:indexPath];    // 如果点击的是分组,则取当前状态的反并更新数据    if (group) {        group.isDelop = !group.isDelop;        [self.tableVIEw reloadData];    }}#pragma mark - 获取点击位置的数据/* * 所点位置是否是分组,返回所点分组数据 **/- (Group *)isGroup:(NSIndexPath *)indexPath {    int num = -1;    NSUInteger index = indexPath.row;        List *List = [_dataList objectAtIndex:indexPath.section];    NSMutableArray *groups = List.groups;    for (Group *group in groups) {        num++;        if (index == num) {            return group;        }        if (group.isDelop) {            num += [group.frIEnds count];            if (index <= num) {                return nil;            }        }    }    return nil;}/* * 所点位置是否是好友,并返回所点好友数据 **/- (FrIEnd *)isFrIEnd:(NSIndexPath *)indexPath {    int num = -1;    NSUInteger index = indexPath.row;        List *List = [_dataList objectAtIndex:indexPath.section];  // 获取点的section    NSMutableArray *groups = List.groups;                      // 获取section下的所有分组    for (Group *group in groups) {        num++;        if (group.isDelop) {            int temp = num;            num += [group.frIEnds count];            if (index <= num) {                int k = index - temp - 1;                return [group.frIEnds objectAtIndex:k];            }        }    }    return nil;}#pragma mark - 初始化cell/* * 设置分组的cell **/- (UItableVIEwCell *)getGroupCell:(UItableVIEw *)tableVIEw and:(NSIndexPath *)indexPath {    Group *NowGroup = [self isGroup:indexPath];    static Nsstring *CellWithIDentifIEr = @"GroupCell";    UItableVIEwCell *cell = [tableVIEw dequeueReusableCellWithIDentifIEr:CellWithIDentifIEr];    if (cell == nil) {        cell = [[UItableVIEwCell alloc] initWithStyle:UItableVIEwCellStyleValue1 reuseIDentifIEr:CellWithIDentifIEr];        cell.backgroundcolor = [UIcolor colorWithRed:227/250.0 green:168/250.0 blue:105/250.0 Alpha:1];    }        cell.textLabel.text = NowGroup.Title;    cell.detailTextLabel.text = NowGroup.detail;    if (NowGroup.isDelop) {        cell.imageVIEw.image = [UIImage imagenamed:@"collect.png"];    }    else {        cell.imageVIEw.image = [UIImage imagenamed:@"tomore.png"];    }    return cell;}/* * 设置好友cell **/- (UItableVIEwCell *)getFrIEndCell:(UItableVIEw *)tableVIEw and:(NSIndexPath *)indexPath {    FrIEnd *NowFrIEnd = [self isFrIEnd:indexPath];    static Nsstring *CellWithIDentifIEr = @"FrIEndCell";    UItableVIEwCell *cell = [tableVIEw dequeueReusableCellWithIDentifIEr:CellWithIDentifIEr];    if (cell == nil) {        cell = [[UItableVIEwCell alloc] initWithStyle:UItableVIEwCellStyleSubTitle reuseIDentifIEr:CellWithIDentifIEr];    }    // 设置cell数据    cell.textLabel.text = NowFrIEnd.name;    cell.detailTextLabel.text = NowFrIEnd.state;    cell.imageVIEw.image = [UIImage imagenamed:NowFrIEnd.image];    return cell;}#pragma mark - 大小样式设置- (CGfloat)tableVIEw:(UItableVIEw *)tableVIEw heightForRowAtIndexPath:(NSIndexPath *)indexPath {    if ([self isGroup:indexPath]) {        return 30;   // 分组高    }    return 40;       // 好友的行高}- (CGfloat)tableVIEw:(UItableVIEw *)tableVIEw heightForheaderInSection:(NSInteger)section {    return 20;}#pragma mark - 所显示的数据/* * 数据初始化构造 **/- (voID)initDataList {    FrIEnd *frIEnd1 = [[FrIEnd alloc] initWithImage:@"back1.jpg" name:@"苦海无涯" states:@"[在线] 哎 心疼!!"];    FrIEnd *frIEnd2 = [[FrIEnd alloc] initWithImage:@"back2.jpg" name:@"段天涯" states:@"[在线] 心疼!!"];    FrIEnd *frIEnd3 = [[FrIEnd alloc] initWithImage:@"back3.jpg" name:@"小妹妹" states:@"[在线] 疼!!"];    FrIEnd *frIEnd4 = [[FrIEnd alloc] initWithImage:@"back4.jpg" name:@"呼哈" states:@"[在线]心疼!!"];        NSMutableArray *array1 = [NSMutableArray arrayWithObjects:frIEnd1, frIEnd2, frIEnd3, frIEnd4, nil];    Group *group1 = [[Group alloc] initWithTitle:@"家人" delop:NO frIEnds:array1];    group1.detail = @"4/4";        FrIEnd *frIEnd5 = [[FrIEnd alloc] initWithImage:@"back5.jpg" name:@"段" states:@"[在线] 心疼!!"];    FrIEnd *frIEnd6 = [[FrIEnd alloc] initWithImage:@"back6.jpg" name:@"小商人" states:@"[在线] 疼!!"];    FrIEnd *frIEnd7 = [[FrIEnd alloc] initWithImage:@"back7.jpg" name:@"大哥" states:@"[离线] 心疼!!"];        NSMutableArray *array2 = [NSMutableArray arrayWithObjects:frIEnd5, frIEnd6, frIEnd7, nil];    Group *group2 = [[Group alloc] initWithTitle:@"朋友" delop:NO frIEnds:array2];    group2.detail = @"2/3";        NSMutableArray *l1 = [NSMutableArray arrayWithObjects:group1, group2, nil];    List *List1 = [[List alloc] initWithTitle:@"我的好友" groups:l1];        FrIEnd *mobile = [[FrIEnd alloc] initWithImage:@"back1.jpg" name:@"我的手机" states:@"[离线]手机未上线"];    NSMutableArray *array = [NSMutableArray arrayWithObjects:mobile, nil];    Group *group = [[Group alloc] initWithTitle:@"我的设备" delop:NO frIEnds:array];    group.detail = @"0/1";        NSMutableArray *l2 = [NSMutableArray arrayWithObjects:group, nil];    List *List2 = [[List alloc] initWithTitle:@"我的手机" groups:l2];        self.dataList = [NSMutableArray arrayWithObjects:List2, List1, nil];}@end
// 好友数据对象@interface FrIEnd : NSObject@property (nonatomic, retain) Nsstring *image;  // 头像@property (nonatomic, retain) Nsstring *name;   // 昵称@property (nonatomic, retain) Nsstring *state;  // 说说@end// 分组对象@interface Group : NSObject@property (nonatomic, assign) BOol isDelop;             // 是否展开@property (nonatomic, retain) Nsstring *Title;          // 分组名称@property (nonatomic, retain) Nsstring *detail;         // 在线状态@property (nonatomic, retain) NSMutableArray *frIEnds;  // 好友列表@end// 整个qq列表@interface List : NSObject@property (nonatomic, retain) Nsstring *Title;          // 列表名称@property (nonatomic, retain) NSMutableArray *groups;   // 列表内分组@end

以上是内存溢出(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

总结

以上是内存溢出为你收集整理的iOS QQ列表效果实现全部内容,希望文章能够帮你解决iOS QQ列表效果实现所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1105937.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存