i have a question, because I am beginner at swift iOS. I don't know how to make a segue from UIViewController
to more UiViewController
. Example : i need to create 3 uiviewcontrollers and navigate to this view from is depends on time(morning,afternoon,night). Schema is here.
if(6:00-9:00)----->View
View if(12:00-15:00)----->View
if(19:00-22:00)----->View
Any help please?
You first need to make sure the four view controllers are in the storyboard. Then you need to make sure that there are three segues that go from the parent view controller to each of the children view controllers. Set the identifiers in story board for each segue to morningSegue, afternoonSegue, and eveningSegue.
Then you need to get the time:
func getTimeOfDay() -> String {
let date = NSDate()
let calendar = NSCalendar.currentCalendar()
let components = calendar.components(.CalendarUnitHour | .CalendarUnitMinute, fromDate: date)
let hour = components.hour
let minutes = components.minute
if (hour > 18)
return "evening"
if (hour > 12)
return "afternoon"
return "morning"
}
Now when the user presses on the button you can write something like this:
if (func getTimeOfDay() == "evening")
self.performSegueWithIdentifier("eveningSegue", sender: self)
Create Manual Segues from Parent view to Child views with different Identifier name and use each segue name according to requirement. You can use button action to check if current time is morning , afternoon or night and call corresponding segue.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.