Search code examples
iosobjective-cswiftandroid-activity

Start a new activity in iOS programmatically


I am creating my application without using StoryBoard, basically creating Widgets (UIViews) and adding them to my rootController.view

self.view.addSubview(view)

My question is fairly basic, but I would like to have some guidance in it. How do I bring up a new activity (as in Android) programmatically and have its rootViewController set to an object of a different UIViewController.

  • Is the concept of a window the same as an activity (in Android)?
  • How can I make the new window/activity slide in from the right, say when a button is clicked?

p.s I am building this application in Swift.


Solution

  • So, I haven't done much Android development, only some small projects. I have done quite a bit of iOS development though. While the concepts are similar, they are not exactly the same.

    The piece of code you posted where you add a subview to your existing superview (current view controller) will not get you the effect you're looking for. What you want to do is push your next view controller on to the screen.

    self.navigationController?.pushViewController(yourNewVC, animated: true)
    

    This will give the effect of sliding the view controller being pushed in from the right as you described.