SajjadZare
SajjadZare

Reputation: 2378

A common bar on top of all Views

I want to have a common bar on top of all Views and put on it an icon for show status of internet connection (in background check it for example every 10 seconds and update this bar)

i don't have any idea for it! how should i do it?

Upvotes: 0

Views: 67

Answers (1)

rizk.taker
rizk.taker

Reputation: 89

Here are two options, relevant depending on what you want to do:

1. If by all views you mean the views of all your view controllers (superviews), you can embed your view controllers in a navigation controller (In Xcode, Editor > Embed in > Navigation Controller). Then you can add a bar button item or label for the status of internet connection.

2. If by all views you don't mean superviews, subclass UIView to create a reusable "top bar." In that class you can add certain properties such as a label to show status of internet connection. Add this subview to any view that you want.

In terms of checking for internet connection, you can use NSNotificationCenter. Wherever you check for network reachability, post a notification:

[[NSNotificationCenter defaultCenter] postNotification:@"networkReachabilityChanged" object:nil];

Then add a listener in any class that has your topbar with label that is going to change depending on network reachability:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(someMethod:) name:@"networkReachabilityChanged" object:nil];

Then trigger the action of changing the label in someMethod's implementation. Hope this helps!

Upvotes: 1

Related Questions