Question: I have created an UIViewController sub class which can either be pushed in a navigation stack of a UINavigationController or presented(modally) from any UIViewController. I need to identify whether my view controller is presented, if it is presented I need to add a toolbar with a close button at the top of the view controller. (else if it is pushed in navigation stack then the default close button will get added, by using that the user can go back.)

In all the available versions say 4.3, 5.0, till 6.0, from inside an UIViewController sub class, Can I assume that the view controller is presented(modally) if the following condition is satisfied.

```
if(self.parentViewController == nil || self.navigationController == nil)

```

Answer: 
To handle this kind of behavior, I usually set/reset a BOOL toggling it in viewWillAppear/viewWillDisappear methods.

By the way, your test condition seems incorrect. I think you should use

```
if(self.parentViewController != nil || self.navigationController != nil)

```

Why can't you just always add the toolbar to your view controller? Is there any case the view is loaded but never presented?
If it was me I'd have a custom init method and use that when creating the vc.

```
vc = [[[MyUIViewControllerSubClass alloc] init] initWithToolbarAndCloseButton:YES];

```