ios - Adding a UICollectionViewController inside UiView -


this question has answer here:

hi new ios development , trying develop simple view imageview, pickerview , collectionview.

enter image description here

i have separate uicollectionviewcontroller, want add uicollectionviewcontroller inside uiview in new mainvc. when run 2 uiviewcontrollers separately works fine. don't know how add uicollectionviewcontroller viview.can me put uicollectionviewcontroller inside uiview or suggestion in simple way.

newmainvc

import uikit  class newmainvc: uiviewcontroller, uipickerviewdatasource, uipickerviewdelegate, uitextfielddelegate  {      @iboutlet weak var dropdown: uipickerview!     @iboutlet weak var textbox: uitextfield!      @iboutlet weak var sensorcollection: uicollectionview!     var values : [anyobject] = []       override func viewdidload() {         super.viewdidload()         self.values.append("main room" anyobject)         self.values.append("dinning room" anyobject)         self.values.append("kitchen" anyobject)       }      override func didreceivememorywarning() {         super.didreceivememorywarning()         // dispose of resources can recreated.     }        func numberofcomponents(in pickerview: uipickerview) -> int {         return 1     }      func pickerview(_ pickerview: uipickerview, numberofrowsincomponent component: int) -> int {         return self.values.count     }      func pickerview(_ pickerview: uipickerview, titleforrow row: int, forcomponent component: int) -> string? {         let titlerow = (values[row] as? string)!         return titlerow     }      func pickerview(_ pickerview: uipickerview, didselectrow row: int, incomponent component: int) {         if values.count > 0 && values.count >= row{             self.textbox.text = self.values[row] as? string             self.dropdown.ishidden = true         }     }         func textfielddidbeginediting(_ textfield: uitextfield) {         //when select text field picker view visible         if(textfield == self.textbox){             self.dropdown.ishidden = false             self.view.endediting(true)         }      }  } 

photoscollectionviewcontroller

import uikit import swiftyjson  class photoscollectionviewcontroller: uicollectionviewcontroller {     @iboutlet var home_collection_view: uicollectionview!       var sensorobjectlist = [sensorobject]()      struct storyboard {         static let photocell = "photocell"         static let headerview = "headerview"         static let showdetailsegue = "showdetail"          static let leftandrightpaddings: cgfloat = 2.0         static let numberofitemsperrow: cgfloat = 3.0     }      override func viewdidload() {         super.viewdidload()          let collectionviewwidth = collectionview?.frame.width        let itemwidth = (collectionviewwidth! - storyboard.leftandrightpaddings) / storyboard.numberofitemsperrow          let layout = collectionviewlayout as! uicollectionviewflowlayout         layout.itemsize = cgsize(width: itemwidth, height: itemwidth+50)          networkcall().requestusinggetmethod(url: "http://122.168.50.5:8181/rest/sitemaps", completion: { response in             print(response)              let jsonresults = json(string: response)             print("------------------------------")             print("homepage link : \(jsonresults[0]["homepage"]["link"].stringvalue)")             print("leaf : \(jsonresults[0]["homepage"]["leaf"].stringvalue)")             print("label : \(jsonresults[0]["label"].stringvalue)")             print("name : \(jsonresults[0]["name"].stringvalue)")             print("link : \(jsonresults[0]["link"].stringvalue)")             print("------------------------------")             self.gethomepagedata(homeurl: jsonresults[0]["link"].stringvalue string!)         })     }      func gethomepagedata(homeurl: string){          networkcall().requestusinggetmethoddictionnary(url: homeurl, completion: { response in             print(response)             let jsonresults = json(string: response)             // print(json8 )             print("-------------------------------------------------------------------------------------------------")             print("label : \(jsonresults["label"].stringvalue)")             //                    print("inside homepage link : \(json8["homepage"]["link"].stringvalue)")             //                    print("inside item array : \(json8["homepage"]["widgets"].arrayvalue)")             //                    print("inside item array2 : \(json8["homepage"]["widgets"][0]["widgets"].arrayvalue)")             result in jsonresults["homepage"]["widgets"][0]["widgets"].arrayvalue {                 print("---------------------------------------------")                 print("label :  \(result["label"].stringvalue)")                 print("widgetid :  \(result["widgetid"].stringvalue)")                 print("icon :  \(result["icon"].stringvalue)")                 print("type :  \(result["type"].stringvalue)")                 print("category :  \(result["item"]["category"].stringvalue)")                 print("link :  \(result["item"]["link"].stringvalue)")                 print("item label :  \(result["item"]["label"].stringvalue)")                 print("type :  \(result["item"]["type"].stringvalue)")                 print("state :  \(result["item"]["state"].stringvalue)")                 print("name :  \(result["item"]["name"].stringvalue)")                  let sensor =  sensorobject()                 sensor.label = result["label"].stringvalue                 sensor.widgetid = result["widgetid"].stringvalue                 sensor.icon = result["icon"].stringvalue                 sensor.category = result["item"]["category"].stringvalue                 sensor.link = result["item"]["link"].stringvalue                 sensor.itemlabel = result["item"]["label"].stringvalue                 sensor.type = result["type"].stringvalue                 sensor.state = result["item"]["state"].stringvalue                 sensor.name = result["item"]["name"].stringvalue                 self.sensorobjectlist.append(sensor)                }             self.home_collection_view.reloaddata()         })           }      // mark: - uicollectionviewdatasource  //    override func numberofsections(in collectionview: uicollectionview) -> int { //        return photocategories.count //    }      override func collectionview(_ collectionview: uicollectionview, numberofitemsinsection section: int) -> int     {         return self.sensorobjectlist.count     }      override func collectionview(_ collectionview: uicollectionview, cellforitemat indexpath: indexpath) -> uicollectionviewcell     {         let cell = collectionview.dequeuereusablecell(withreuseidentifier: storyboard.photocell, for: indexpath) as! photocell          let sensor = self.sensorobjectlist[indexpath.row]          cell.imagename = "ic_home_white"         cell.imagetext = sensor.name         cell.statustext = sensor.state         cell.titletext = sensor.itemlabel          return cell     }       // mark: - uicollectionviewdelegate      override func collectionview(_ collectionview: uicollectionview, didselectitemat indexpath: indexpath) {   //        let category = self.photocategories[indexpath.section] //        let image = uiimage(named: category.imagenames[indexpath.item]) //         //        self.performsegue(withidentifier: storyboard.showdetailsegue, sender: image)     }   } 

can me put uicollectionviewcontroller inside uiview or suggestion in simple way.

you can add container view mainvc , embed collection view container view


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -