日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

QQList列表功能实现

發布時間:2024/7/19 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 QQList列表功能实现 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1.模型

@class?FriendsModel;

@interface?GroupModel :?NSObject


@property?(nonatomic, copy)?NSString?*name;

@property?(nonatomic, copy)?NSString?*online;

@property?(nonatomic, strong)?NSArray?*friends;

@property?(nonatomic, strong) FriendsModel *friendModel;

@property?(nonatomic, assign)?BOOL?isOpen;

- (instancetype)initWithDict:(NSDictionary?*)dict;

+ (instancetype)GroupWithDict:(NSDictionary?*)dict;


@end


#import?"FriendsModel.h"

@implementation?GroupModel


- (instancetype)initWithDict:(NSDictionary?*)dict{

? ??if?(self?= [super?init]) {

? ? ? ? [self?setValuesForKeysWithDictionary:dict];

? ? ? ??NSMutableArray?*muArray = [NSMutableArray?array];

? ? ? ??for?(NSDictionary?*dict?in?self.friends) {

? ? ? ? ? ? FriendsModel *model = [FriendsModel friendWithDict:dict];

? ? ? ? ? ? [muArray addObject:model];

? ? ? ? }

? ? ? ??self.friends?= muArray;

? ? }

? ??return?self;

}

+ (instancetype)GroupWithDict:(NSDictionary?*)dict

{

? ??return?[[self?alloc]?initWithDict:dict];

}


@end


@interface?FriendsModel :?NSObject


@property?(nonatomic,?copy)?NSString?*icon;

@property?(nonatomic,?copy)?NSString?*name;

@property?(nonatomic,?copy)?NSString?*intro;

@property?(nonatomic,?assign)?BOOL?isVip;


- (instancetype)initWithDict:(NSDictionary?*)dict;

+ (instancetype)friendWithDict:(NSDictionary?*)dict;

@end




#import?"FriendsModel.h"


@implementation?FriendsModel

- (instancetype)initWithDict:(NSDictionary?*)dict{

? ??if?(self?= [super?init]) {

? ? ? ? [self?setValuesForKeysWithDictionary:dict];

? ? }

? ??return?self;

}

+ (instancetype)friendWithDict:(NSDictionary?*)dict{

? ??return?[[self?alloc]?initWithDict:dict];

}

@end



2.tableView UITableViewHeaderFooterView
的繼承

@protocol HeaderViewDelegate <NSObject>


@optional

- (void)clickView;

@end


@interface HeaderView : UITableViewHeaderFooterView

@property (nonatomic,assign)id<HeaderViewDelegate> delegate;


@property (nonatomic,strong) GroupModel *groupModel;

+ (instancetype)headerView:(UITableView *)tableView;

@end


#import "HeaderView.h"

#import “GroupModel.h"


@implementation HeaderView{

? ?UIButton *_arrowBtn;

? ?UILabel? *_label;

}


+ (instancetype)headerView:(UITableView *)tableView

{

? ?staticNSString *identifier =@"header";

? ?HeaderView *header = [tableViewdequeueReusableCellWithIdentifier:identifier];

? ?if (!header) {

? ? ? ? header = [[HeaderViewalloc]initWithReuseIdentifier:identifier];

? ? }

? ?return header;

}


- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier

{

? ?if (self = [superinit]) {

? ? ? ? UIButton *button = [UIButtonbuttonWithType:UIButtonTypeCustom];

? ? ? ? [button setBackgroundImage:[UIImageimageNamed:@"header_bg"]forState:UIControlStateNormal];

? ? ? ? [button setBackgroundImage:[UIImageimageNamed:@"header_bg_highlighted"]forState:UIControlStateHighlighted];

? ? ? ? [button setImage:[UIImageimageNamed:@"arrow"]forState:UIControlStateNormal];

? ? ? ? [button setTitleColor:[UIColorblackColor]forState:UIControlStateNormal];

? ? ? ? button.contentEdgeInsets =UIEdgeInsetsMake(0,10,0, 0);

? ? ? ? button.contentHorizontalAlignment =UIControlContentHorizontalAlignmentLeft;

? ? ? ? button.titleEdgeInsets =UIEdgeInsetsMake(0,10,0, 0);

? ? ? ? button.imageView.contentMode =UIViewContentModeCenter;

? ? ? ? [button addTarget:selfaction:@selector(buttonAction)forControlEvents:UIControlEventTouchUpInside];

? ? ? ? //超出范圍的圖片不要剪切

? ? ? ? button.imageView.clipsToBounds =NO;

? ? ? ?_arrowBtn = button;

? ? ? ? [selfaddSubview:_arrowBtn];

? ? ? ? //創建label,顯示當前在線人數

? ? ? ?UILabel *labelRight = [[UILabelalloc]init];

? ? ? ? labelRight.textAlignment =NSTextAlignmentCenter;

? ? ? ?_label = labelRight;

? ? ? ? [selfaddSubview:_label];

? ? }

? ? return self;

}



#pragma mark - buttonAction

- (void)buttonAction

{

? ?self.groupModel.isOpen = !self.groupModel.isOpen;

? ?if ([self.delegaterespondsToSelector:@selector(clickView)]) {

? ? ? ? [self.delegateclickView];

? ? }

}



- (void)didMoveToSuperview

{

? ? //通知相關視圖他們的上級視圖已經變化是當某個子控件載入到父控件上得時候調用

?? ?

? ? _arrowBtn.imageView.transform =self.groupModel.isOpen ?

CGAffineTransformMakeRotation(M_PI_2) :CGAffineTransformMakeRotation(0);

?? ?

}


//布局

- (void)layoutSubviews

{

? ? [superlayoutSubviews];

? ? _arrowBtn.frame =self.bounds;

? ? _label.frame =CGRectMake(self.frame.size.width - 70, 0, 60,self.frame.size.height);

}


//賦值

- (void)setGroupModel:(GroupModel *)groupModel

{

? ? _groupModel = groupModel;

? ? [_arrowBtn setTitle:_groupModel.name forState:UIControlStateNormal];

? ? _label.text = [NSString stringWithFormat:@"%@/%lu",_groupModel.online,(unsignedlong)_groupModel.friends.count];

?? ?

}


3.控制器

#import "ListTableViewController.h"

#import "GroupModel.h"

#import "FriendsModel.h"

#import "HeaderView.h"

#import "ViewController.h"

@interface ListTableViewController ()<HeaderViewDelegate>

@property (nonatomic, strong)NSArray *dataArray;

@end


@implementation ListTableViewController

//懶載入

- (NSArray *)dataArray{

? ?if (!_dataArray) {

? ? ? ? NSString *path = [[NSBundlemainBundle]pathForResource:@"friends.plist"ofType:nil];

? ? ? ?NSArray *array = [NSArrayarrayWithContentsOfFile:path];

? ? ? ? NSMutableArray *muArray = [NSMutableArrayarrayWithCapacity:array.count];

? ? ? ?for (NSDictionary *dictin array) {

? ? ? ? ? ? GroupModel *groupModel = [GroupModel GroupWithDict:dict];

? ? ? ? ? ? [muArray addObject:groupModel];

? ? ? ? }

? ? ? ?_dataArray = [muArraycopy];

? ? }

? ? return_dataArray;

?? ?

?? ?

}

- (void)viewDidLoad

{

? ? [superviewDidLoad];

?? ?

? ? self.tableView.sectionHeaderHeight =40;//自己定義了sectionHeader一定要設置高

? ? [selfclipExtraCellLine:self.tableView];//數據不夠,去掉以下多余的表格線

}



#pragma mark - Table view data source


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

{

? ? return self.dataArray.count;

}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

? ? GroupModel *groupModel =self.dataArray[section];

? ?NSInteger count = groupModel.isOpen ? groupModel.friends.count :0;

? ?return count;

}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

? ?staticNSString *identifier =@"friendCell";

? ?UITableViewCell *cell = [tableViewdequeueReusableCellWithIdentifier:identifier];

? ?if (!cell) {

? ? ? ? cell = [[UITableViewCellalloc]initWithStyle:UITableViewCellStyleSubtitlereuseIdentifier:identifier];

?? ? ? ?

? ? }

? ? GroupModel *groupModel =self.dataArray[indexPath.section];

? ? FriendsModel *friendModel = groupModel.friends[indexPath.row];

? ? cell.imageView.image = [UIImage imageNamed:friendModel.icon];

? ? cell.textLabel.text = friendModel.name;

? ? cell.detailTextLabel.text = friendModel.intro;

?? ?

? ?return cell;

}

#pragma mark - UITableView delegate

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section

{

? ?HeaderView *header = [HeaderViewheaderView:tableView];

? ? header.delegate =self;

? ? header.groupModel =self.dataArray[section];

? ?return header;

}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{

? ? ViewController *viewCtrl = [[ViewControlleralloc]init];

? ? //viewCtrl.view.backgroundColor = [UIColor redColor];

? ? [self.navigationControllerpushViewController:viewCtrlanimated:NO];

}


- (void)clickView

{

? ? [self.tableViewreloadData];

}


#pragma mark - 去掉多余的線

- (void)clipExtraCellLine:(UITableView *)tableView

{

? ?UIView *view = [[UIViewalloc]init];

? ? view.backgroundColor = [UIColorclearColor];

? ? [self.tableViewsetTableFooterView:view];

}


/*

?設置視圖控制顏色

?

?self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];

?self.window.backgroundColor = [UIColor whiteColor];

?ListTableViewController *listVC = [[ListTableViewController alloc] init];

?UINavigationController *navCtrl = [[UINavigationController alloc] initWithRootViewController:listVC];

?self.window.rootViewController = navCtrl;

?[self.window makeKeyAndVisible];

?*/


素材下載地址:http://download.csdn.net/detail/baitxaps/8934111

轉載于:https://www.cnblogs.com/gccbuaa/p/7391243.html

總結

以上是生活随笔為你收集整理的QQList列表功能实现的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。