Files
yinmeng-ios/xplan-ios/Main/Home/View/XPFindNewFriendViewController.m
chenshuanglin 1414d2fea7 完善首页UI
2023-03-06 18:41:25 +08:00

155 lines
5.2 KiB
Objective-C

//
// XPFindNewFriendViewController.m
// xplan-ios
//
// Created by XY on 2023/3/6.
//
#import "XPFindNewFriendViewController.h"
///Third
#import <Masonry/Masonry.h>
#import "NSArray+Safe.h"
///View
#import "XPFindNewFriendTableViewCell.h"
#import "XPHomeListEmptyTableViewCell.h"
#import "XPHomeBannerTableViewCell.h"
///VC
#import "XPWebViewController.h"
#import "XPRoomViewController.h"
///Model
#import "HomePlayRoomModel.h"
@interface XPFindNewFriendViewController ()<UITableViewDelegate, UITableViewDataSource, XPHomeBannerTableViewCellDelegate>
///列表
@property (nonatomic,strong) UITableView *tableView;
@property (nonatomic, copy) void(^scrollCallback)(UIScrollView *scrollView);
@end
@implementation XPFindNewFriendViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self initSubViews];
[self initSubViewConstraints];
}
- (BOOL)isHiddenNavBar {
return YES;
}
#pragma mark - Private Method
- (void)initSubViews {
self.view.backgroundColor = [UIColor clearColor];
[self.view addSubview:self.tableView];
}
- (void)initSubViewConstraints {
[self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.view);
}];
}
#pragma mark - UITableViewDelegate And UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.roomList.count > 0 ? self.roomList.count : 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (self.roomList.count > 0) {
HomePlayRoomModel * model = [self.roomList safeObjectAtIndex1:indexPath.row];
return 105;
}
return 300;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (self.roomList.count > 0) {
HomePlayRoomModel * model = [self.roomList safeObjectAtIndex1:indexPath.row];
XPFindNewFriendTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([XPFindNewFriendTableViewCell class])];
if (cell == nil) {
cell = [[XPFindNewFriendTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass([XPFindNewFriendTableViewCell class])];
}
cell.roomInfo = model;
return cell;
}
XPHomeListEmptyTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([XPHomeListEmptyTableViewCell class])];
if (cell == nil) {
cell = [[XPHomeListEmptyTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass([XPHomeListEmptyTableViewCell class])];
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
if (self.roomList.count > 0) {
HomePlayRoomModel * model = [self.roomList safeObjectAtIndex1:indexPath.row];
if (!model.isBanner && model.uid.integerValue > 0) {
[XPRoomViewController openRoom:model.uid fromNick:model.title fromType:UserEnterRoomFromType_Home_Recommend fromUid:nil viewController:self];
}
}
}
#pragma mark - XPHomeBannerTableViewCellDelegate
- (void)xPHomeBannerTableViewCell:(XPHomeBannerTableViewCell *)view didClickBanner:(HomeBannerInfoModel *)info {
switch (info.skipType) {
case HomeBannerInfoSkipType_Room:
{
if (info.skipUri.length > 0) {
[XPRoomViewController openRoom:info.skipUri viewController:self];
}
}
break;
case HomeBannerInfoSkipType_Web:
{
XPWebViewController *vc = [[XPWebViewController alloc]init];
vc.url = info.skipUri;
[self.navigationController pushViewController:vc animated:YES];
}
break;
default:
break;
}
}
#pragma mark - JXPagingViewListViewDelegate
- (UIView *)listView {
return self.view;
}
- (UIScrollView *)listScrollView {
return self.tableView;
}
- (void)listViewDidScrollCallback:(void (^)(UIScrollView *))callback {
self.scrollCallback = callback;
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
self.scrollCallback(scrollView);
}
#pragma mark - Getters And Setters
- (void)setRoomList:(NSArray *)roomList {
_roomList = roomList;
[self.tableView reloadData];
}
- (UITableView *)tableView {
if (!_tableView) {
_tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
_tableView.delegate = self;
_tableView.dataSource = self;
_tableView.tableFooterView = [UIView new];
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
_tableView.backgroundColor = [UIColor clearColor];
if (@available(iOS 11.0, *)) {
_tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
}
[_tableView registerClass:[XPFindNewFriendTableViewCell class] forCellReuseIdentifier:NSStringFromClass([XPFindNewFriendTableViewCell class])];
[_tableView registerClass:[XPHomeListEmptyTableViewCell class] forCellReuseIdentifier:NSStringFromClass([XPHomeListEmptyTableViewCell class])];
}
return _tableView;
}
@end