user3662992
user3662992

Reputation: 688

Swift : One Navigation bar item

I'm new to swift and I have problem with navigation bar item.

I've :

1 Button"post"

4 toolbar Items Text and Image and two others

4 Containers hocked up with 4 view controllers

Each toolbar item hocked to 1 containers(view-controller) and so on for the others.

My Question is How to make The post button switch view controller according to the post type ( image or text).

enter image description here

Upvotes: 1

Views: 196

Answers (1)

Samuel Cortez
Samuel Cortez

Reputation: 158

You can track the action your ToolBar Item (Post) will have according with any situation you want to. But then you probably gonna use some booleans. Create a connection from Storyboard to its file class of type Action, not outlet. In the action method created, you can check if it is supposed to post text or image, like:

if shouldPostText{
    // post text
}else{
    // post image
}

The boolean value you can change when text/image buttons are pressed. Then create two segues in storyboard, both linking your UIViewController to the view controller of text and to the view controller of image. Name the segues differently (like seguetoText and segueToImage) and do like:

if shouldPostText{
    self.performSegueWithIdentifier("segueToText", sender: self)
}else{
    self.performSegueWithIdentifier("segueToImage", sender: self)
}

I'm not quite sure of what you were asking for but it seems like was this.

Upvotes: 1

Related Questions