ios - Locating Storyboard Views by code -


i've created view code 2 uicollectionviews. created them in storyboard , need locate them code. how did it:

        topproducts = uicollectionview(frame: cgrect(x: 8, y: scrollviewheight + 166, width: viewwidth - 8, height: 120))     contentscrollview.addsubview(topproducts) 

app crashes , error shows in console:

* terminating app due uncaught exception 'nsinvalidargumentexception', reason: 'uicollectionview must initialized non-nil layout parameter' * first throw call stack: ( 0 corefoundation 0x000000010271526b exceptionpreprocess + 171 1 libobjc.a.dylib 0x000000010160af41 objc_exception_throw + 48 2 corefoundation 0x0000000102789ba5 +[nsexception raise:format:] + 197 3 uikit 0x0000000105d14a39 -[uicollectionview initwithframe:collectionviewlayout:] + 81 4 uikit 0x0000000105d149e2 -[uicollectionview initwithframe:] + 58 5 jahanco catalog 0x0000000100747bfd _t0so16uicollectionviewcabsc6cgrectv5frame_tcfcto + 77 6 jahanco catalog 0x0000000100744f24 _t0so16uicollectionviewcabsc6cgrectv5frame_tcfc + 100 7 jahanco catalog 0x00000001007446f0 _t015jahanco_catalog9slideviewc11viewdidloadyyf + 9936 8 jahanco catalog 0x0000000100744fa4 _t015jahanco_catalog9slideviewc11viewdidloadyyfto + 36 9 uikit 0x000000010542fd93 -[uiviewcontroller loadviewifrequired] + 1235 10 uikit 0x0000000105476cd4 -[uinavigationcontroller _updatescrollviewfromviewcontroller:toviewcontroller:] + 68 11 uikit 0x0000000105477010 -[uinavigationcontroller _starttransition:fromviewcontroller:toviewcontroller:] + 153 12 uikit 0x0000000105478127 -[uinavigationcontroller _startdeferredtransitionifneeded:] + 841 13 uikit 0x0000000105479388 -[uinavigationcontroller __viewwilllayoutsubviews] + 115 14 uikit 0x00000001056c26d9 -[uilayoutcontainerview layoutsubviews] + 231 15 uikit 0x000000010536321e -[uiview(calayerdelegate) layoutsublayersoflayer:] + 1331 16 quartzcore 0x0000000103375c92 -[calayer layoutsublayers] + 153 17 quartzcore 0x0000000103379d79 _zn2ca5layer16layout_if_neededepns_11transactione + 401 18 quartzcore 0x0000000103302851 _zn2ca7context18commit_transactionepns_11transactione + 385 19 quartzcore 0x000000010332e1c2 _zn2ca11transaction6commitev + 500 20 uikit 0x00000001052b11de __34-[uiapplication _firstcommitblock]_block_invoke_2 + 141 21 corefoundation 0x00000001026b82ac __cfrunloop_is_calling_out_to_a_block + 12 22 corefoundation 0x000000010269cadb __cfrunloopdoblocks + 203 23 corefoundation 0x000000010269c2b4 __cfrunlooprun + 1300 24 corefoundation 0x000000010269bb29 cfrunlooprunspecific + 409 25 graphicsservices 0x000000010aa059c6 gseventrunmodal + 62 26 uikit 0x00000001052959a4 uiapplicationmain + 159 27 jahanco catalog 0x0000000100754ed7 main + 55 28 libdyld.dylib 0x000000010750f621 start + 1 29 ??? 0x0000000000000001 0x0 + 1 ) libc++abi.dylib: terminating uncaught exception of type nsexception (lldb)

following way create collectionview programatically

class gridviewcontroller: uiviewcontroller, uicollectionviewdatasource, uicollectionviewdelegateflowlayout, uicollectionviewdelegate {  override func viewdidload() {     super.viewdidload()      let flowlayout = uicollectionviewflowlayout()     //to set scroll direction     flowlayout.scrolldirection = .horizontal      let collectionview = uicollectionview(frame: self.view.bounds, collectionviewlayout: flowlayout)     collectionview.register(uicollectionviewcell.self, forcellwithreuseidentifier: "collectioncell")     collectionview.delegate = self     collectionview.datasource = self     collectionview.backgroundcolor = uicolor.cyan      self.view.addsubview(collectionview) }  func collectionview(_ collectionview: uicollectionview, numberofitemsinsection section: int) -> int {     return 20 }  func collectionview(_ collectionview: uicollectionview, cellforitemat indexpath: indexpath) -> uicollectionviewcell {     let cell = collectionview.dequeuereusablecell(withreuseidentifier: "collectioncell", for: indexpath indexpath)      cell.backgroundcolor = uicolor.green     return cell }  func collectionview(_ collectionview: uicollectionview, layout collectionviewlayout: uicollectionviewlayout, sizeforitemat indexpath: indexpath) -> cgsize {     return cgsize(width: 50, height: 50) }  func collectionview(_ collectionview: uicollectionview, layout collectionviewlayout: uicollectionviewlayout, insetforsectionat section: int) -> uiedgeinsets {     return uiedgeinsets(top: 5, left: 5, bottom: 5, right: 5) }  } 

Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -