Day Nineth: 9_swiftdemo_embedseguewithpageviewcontroller

Source: Internet
Author: User

1 Import UIKit2 3 classViewcontroller:uiviewcontroller, Uipageviewcontrollerdelegate, Uipageviewcontrollerdatasource {4 5@IBOutlet weak var redbtn:uibutton!6@IBOutlet weak var yellowbtn:uibutton!7@IBOutlet weak var bluebtn:uibutton!8     9var Vcarr =Nsmutablearray.init ()Tenvar pagevc:uipageviewcontroller! One var currentindex:int { A         Get { -             ifredbtn.isselected { -                 returnRedbtn.tag the}Else ifyellowbtn.isselected { -                 returnYellowbtn.tag -}Else ifbluebtn.isselected { -                 returnBluebtn.tag +}Else { -                 return 0 +             } A         } at          -         Set { -             ifNewValue = =0 { -redbtn.isselected =true -yellowbtn.isselected =false -bluebtn.isselected =false in}Else ifNewValue = =1 { -redbtn.isselected =false toyellowbtn.isselected =true +bluebtn.isselected =false -}Else ifNewValue = =2 { theredbtn.isselected =false *yellowbtn.isselected =false $bluebtn.isselected =truePanax Notoginseng             } -         } the     } +      A      the     Overridefunc viewdidload () { + super.viewdidload () -         //additional setup after loading the view, typically from a nib. $          $Let SB = Uistoryboard.init (name:"Main", Bundle:nil) -          -          forTempidinch["Redviewcontroller","Yellowviewcontroller","Blueviewcontroller"] { theLet TEMPVC =Sb.instantiateviewcontroller (withidentifier:tempid) - Vcarr.add (TEMPVC)Wuyi         } the          -PAGEVC = Self.childViewControllers.first as! uipageviewcontroller! WuPagevc.Delegate= Self -Pagevc.datasource = Self AboutPagevc.setviewcontrollers ([Vcarr.Object(at:0) as! Uiviewcontroller], direction:. Forward, Animated:true, Completion:nil) $Currentindex =0 -     } -  - @IBAction Func handlebtnpressed (_ Sender:uibutton) { A         ifCurrentindex! =Sender.tag { +Currentindex =Sender.tag thePagevc.setviewcontrollers ([Vcarr.Object(At:currentindex) as! Uiviewcontroller], direction:. Forward, Animated:false, Completion:nil) -         } $     } the      the     Overridefunc didreceivememorywarning () { the super.didreceivememorywarning () the         //Dispose of any resources the can be recreated. -     } in  theFunc Pageviewcontroller (_ Pageviewcontroller:uipageviewcontroller, Viewcontrollerbefore ViewController: Uiviewcontroller, Uiviewcontroller? { theLet index =Vcarr.index (Of:viewcontroller) About         ifIndex-1<0 { the             returnNil the}Else { the             returnVcarr.Object(At:index-1) as?Uiviewcontroller +         } -     } the     BayiFunc Pageviewcontroller (_ Pageviewcontroller:uipageviewcontroller, Viewcontrollerafter ViewController: Uiviewcontroller, Uiviewcontroller? { theLet index =Vcarr.index (Of:viewcontroller) the         ifIndex +1>=Vcarr.count { -             returnNil -}Else { the             returnVcarr.Object(At:index +1) as?Uiviewcontroller the         } the     } the      - Func Pageviewcontroller (_ Pageviewcontroller:uipageviewcontroller, didfinishanimating Finished:bool, PreviousV Iewcontrollers: [Uiviewcontroller], transitioncompleted completed:bool) { theCurrentindex = Vcarr.index (of:pageviewcontroller.viewcontrollers?[0] asAny ) the     } the}

Day Nineth: 9_swiftdemo_embedseguewithpageviewcontroller

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.