From 5b0c5e90f6aeebf9ea986ec5338da395e74ac31f Mon Sep 17 00:00:00 2001 From: 葛建军 Date: Sat, 20 May 2017 17:26:04 +0800 Subject: [PATCH] 资源首页数据填充 --- YouerLiveVideo/YouerLiveVideo.xcodeproj/project.pbxproj | 2 +- YouerLiveVideo/YouerLiveVideo/Base.lproj/Main.storyboard | 159 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------------------------------- YouerLiveVideo/YouerLiveVideo/controllers/Resource/ResourceViewController.swift | 175 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------- YouerLiveVideo/YouerLiveVideo/util/utiles.swift | 2 +- 4 files changed, 256 insertions(+), 82 deletions(-) diff --git a/YouerLiveVideo/YouerLiveVideo.xcodeproj/project.pbxproj b/YouerLiveVideo/YouerLiveVideo.xcodeproj/project.pbxproj index b6c2434..083943f 100644 --- a/YouerLiveVideo/YouerLiveVideo.xcodeproj/project.pbxproj +++ b/YouerLiveVideo/YouerLiveVideo.xcodeproj/project.pbxproj @@ -589,8 +589,8 @@ BFBB83A81ECAE35E008B404B /* LeadViewController.swift */, 5904FC601ECA930D00E631FF /* MViewController.swift */, 5904FC431ECA8B8C00E631FF /* HomePage */, - 5904FC441ECA8B8C00E631FF /* MicroCourse */, 5904FC461ECA8B8C00E631FF /* Resource */, + 5904FC441ECA8B8C00E631FF /* MicroCourse */, 5904FC481ECA8B8C00E631FF /* TVStation */, BFBB83D81ECC445D008B404B /* User */, ); diff --git a/YouerLiveVideo/YouerLiveVideo/Base.lproj/Main.storyboard b/YouerLiveVideo/YouerLiveVideo/Base.lproj/Main.storyboard index 538d280..9258dd6 100644 --- a/YouerLiveVideo/YouerLiveVideo/Base.lproj/Main.storyboard +++ b/YouerLiveVideo/YouerLiveVideo/Base.lproj/Main.storyboard @@ -1,5 +1,5 @@ - - + + @@ -42,18 +42,57 @@ - + + + + + + + + + + + + + + + + + + + + - + - + - + @@ -80,6 +119,7 @@ + + + + + + + @@ -127,67 +174,77 @@ - + + - - - - - - - - - - + - - - - - - - - + - + + + + + + + + + + + + + + + - - - + + + - + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/YouerLiveVideo/YouerLiveVideo/controllers/Resource/ResourceViewController.swift b/YouerLiveVideo/YouerLiveVideo/controllers/Resource/ResourceViewController.swift index 6ed4a64..b5fac17 100644 --- a/YouerLiveVideo/YouerLiveVideo/controllers/Resource/ResourceViewController.swift +++ b/YouerLiveVideo/YouerLiveVideo/controllers/Resource/ResourceViewController.swift @@ -8,47 +8,153 @@ import UIKit -class ResourceViewController: UIViewController { - +class ResourceViewController: UIViewController,UITableViewDelegate,UITableViewDataSource,UISearchControllerDelegate,UISearchResultsUpdating { + @IBOutlet var tableView: UITableView! + + @IBOutlet var grayView: UIView! + @IBOutlet var searchTableView: UITableView! + @IBOutlet var searchTableHeight: NSLayoutConstraint! + + var searchController:UISearchController! + var dataSetAry:[String]=["葛建军","张道峰","徐晓杰","左承","段合江"] + var searchAry:[String]=[] + var currentPage:Int=0 //当前页数,每次取十个数据 + var resourceData:[MicroCourseModel]=[] override func viewDidLoad() { super.viewDidLoad() self.configTheme() - // Do any additional setup after loading the view. + addSearchController() + addRefresh() + self.refreshLivesAction(tag: self.currentPage, completionHandler: { (success) in + if success{ + self.tableView.reloadData() + } + }) } - - override func didReceiveMemoryWarning() { - super.didReceiveMemoryWarning() - // Dispose of any resources that can be recreated. + func addSearchController(){ + self.definesPresentationContext=true + searchController=UISearchController(searchResultsController: nil) + searchController.delegate=self + searchController.searchResultsUpdater=self + searchController.searchBar.barTintColor=UIColor.groupTableViewBackground + searchController.searchBar.placeholder="搜索" + //设置UISearchController的显示属性,以下3个属性默认为YES + //搜索时,背景变暗色 + self.searchController.dimsBackgroundDuringPresentation=false + //搜索时,背景变模糊 + // self.searchController.obscuresBackgroundDuringPresentation=false + //点击搜索的时候,是否隐藏导航栏 + // searchController.hidesNavigationBarDuringPresentation=true + //位置 + searchController.searchBar.frame=CGRect(x: self.searchController.searchBar.frame.origin.x, y: self.searchController.searchBar.frame.origin.y, width: self.searchController.searchBar.frame.size.width, height: 44.0); + // self.view.addSubview(searchController.searchBar) + searchTableView.tableHeaderView=searchController.searchBar } - - - /* - // MARK: - Navigation - - // In a storyboard-based application, you will often want to do a little preparation before navigation - override func prepare(for segue: UIStoryboardSegue, sender: Any?) { - // Get the new view controller using segue.destinationViewController. - // Pass the selected object to the new view controller. + func addRefresh(){ + let header=MJRefreshNormalHeader(refreshingBlock: { + //下拉刷新 + self.currentPage=0 + self.resourceData.removeAll() + self.refreshLivesAction(tag: self.currentPage, completionHandler: { (success) in + if success{ + self.tableView.reloadData() + } + self.tableView.mj_header.endRefreshing() + }) + }) + header?.lastUpdatedTimeLabel.isHidden=true + tableView.mj_header=header + tableView.mj_footer=MJRefreshBackNormalFooter(refreshingBlock: { + //上拉加载更多 + self.refreshLivesAction(tag: self.currentPage, completionHandler: { (success) in + if success{ + self.tableView.reloadData() + } + self.tableView.mj_footer.endRefreshing() + }) + }) + } + // MARK: - 刷新数据接口 + func refreshLivesAction(tag:Int,completionHandler:@escaping (Bool) -> ()){ + let parameters:Dictionary=["type":1 as AnyObject,"pageIndex":tag as AnyObject,"pageSize":1 as AnyObject] + AppDelegate.instance().httpServer.getHotRescourse(parameters: parameters) { (str, error) in + var success:Bool=true + if error==nil { + if JSON.fromString(jsonString: str)!["status"].intValue == 1{ + httpJsonResule(jsonString: str, error: error, successHandler: { (json) in + if JSON.fromString(jsonString: str)!["data"].arrayValue.count>0{ + self.currentPage+=1 + } + for item in JSON.fromString(jsonString: str)!["data"].arrayValue { + self.resourceData.append(MicroCourseModel(j: item)) + } + success=true + }, failHandler: { (error) in + success=false + appRootViewController().view.makeToast("获取资源失败:\(error.localizedDescription)") + }) + }else{ + success=false + appRootViewController().view.makeToast("获取资源失败:\(JSON.fromString(jsonString: str)!["message"].stringValue)") + } + }else{ + success=false + appRootViewController().view.makeToast("获取资源失败:\(error!.description)") + } + completionHandler(success) + } } - */ - -} - -extension ResourceViewController:UITableViewDelegate,UITableViewDataSource{ func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { - return 10 + if tableView==searchTableView{ + return searchAry.count + }else{ + return resourceData.count + } + } + func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + if tableView==searchTableView { + let cell=tableView.dequeueReusableCell(withIdentifier: "cell") + cell?.textLabel?.text=searchAry[indexPath.row] + return cell! + }else{ + let cell=tableView.dequeueReusableCell(withIdentifier: "identifier") as! ResourceViewControllerTableViewCell + cell.setUpWith(item: resourceData[indexPath.row]) + return cell + } } - func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { - + if tableView==searchTableView { + let vc = UIStoryboard(name: "HomePage", bundle: nil).instantiateViewController(withIdentifier: "RankingTableViewController") as! RankingTableViewController + self.navigationController?.pushViewController(vc, animated: true) + } } - - func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! ResourceViewControllerTableViewCell - return cell + //取消键盘输入状态 + @IBAction func cancleSearchActivit(_ sender: UITapGestureRecognizer) { + searchController.isActive=false + } + func willPresentSearchController(_ searchController: UISearchController) { + grayView.isHidden=false } + func willDismissSearchController(_ searchController: UISearchController) { + searchTableHeight.constant=44 + grayView.isHidden=true + } + //谓词搜索过滤 + func updateSearchResults(for searchController: UISearchController) { + let searchString=searchController.searchBar.text + let predicate=NSPredicate(format: "SELF CONTAINS[c] %@", searchString!) + searchAry=(dataSetAry as NSArray).filtered(using: predicate) as! [String] + if CGFloat((searchAry.count+1)*44)>(getScreenHeight()-64){ + searchTableHeight.constant=getScreenHeight()-64 + }else{ + searchTableHeight.constant=CGFloat((searchAry.count+1)*44) + } + searchTableView.reloadData() + } + } + extension ResourceViewController:UICollectionViewDelegate,UICollectionViewDelegateFlowLayout,UICollectionViewDataSource{ func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { @@ -66,7 +172,18 @@ extension ResourceViewController:UICollectionViewDelegate,UICollectionViewDelega } class ResourceViewControllerTableViewCell:UITableViewCell{ - + @IBOutlet var iconImageView: UIImageView! + @IBOutlet var titleLabel: UILabel! + @IBOutlet var updateTeacherLabel: UILabel! + @IBOutlet var timeLabel: UILabel! + @IBOutlet var downLoadCountLabel: UILabel! + func setUpWith(item: MicroCourseModel){ + iconImageView.sd_setImage(with: URL(string: item.f_Img), placeholderImage: UIImage(named: "icon_course_placeholder")) + titleLabel.text=item.f_Title + updateTeacherLabel.text="上传者:\(item.f_CreatorName) 老师" + timeLabel.text=item.f_CreatorTime + downLoadCountLabel.text="\(item.f_DownloadSum)" + } } diff --git a/YouerLiveVideo/YouerLiveVideo/util/utiles.swift b/YouerLiveVideo/YouerLiveVideo/util/utiles.swift index f96d3bb..939dffe 100644 --- a/YouerLiveVideo/YouerLiveVideo/util/utiles.swift +++ b/YouerLiveVideo/YouerLiveVideo/util/utiles.swift @@ -49,7 +49,7 @@ class AlertController { } class Theme{ static func topBarColor()->UIColor{ - return UIColorFromRGB(0xff6533)//UIColorFromRGB(0xff9b34)f6595f + return UIColorFromRGB(0x1CA2FF)//UIColorFromRGB(0xff9b34)f6595f } ///按钮样式 static func configButton(_ button:UIButton){ -- libgit2 0.21.0