UINavigationBar : repaint? - ios

I'm facing a problem I don't understand.
In my main view, I have a button heading to another view. Everything is embedded in a NavigationController.
I successfully changed the background image of my NavigationBar in my main view. But when I click on the button to display my other view, my NavigationBar's isn't repainted although I'm using this code :
- (IBAction) toOtherView : (id) sender
{
if(!otherView) otherView = [[OtherViewController alloc] initWithNibName:#"OtherViewController" bundle:nil];
[self.navigationController pushViewController:otherView animated:NO];
}
However, I also have a Dark Info button on my main view (I choosed the default Utility Application at first). It flips to another view and when I come back to my main view, the NavigationBar image has been changed. So I guess it's a problem of repaint. But what can I do here ?
Thanks a lot for your advices.

Related

Blank screen before and after the UIWebview load and next view load iOS Objective C

I have two view controllers. In first view controller, I click a button and a webview loads. Before loading web view, it shows a black screen and it goes immediately and the webviews load. Again, when I go from my webview to another view controller, I see the same black screen comes and goes immediately.
PS : This code is not written by me, and it's a little messy so I am not able to paste code here.
Please let me know if you can think of any proper reasoning why its happening and how can I resolve it?
Is there any way i can check for number of view controllers in the stack? Because sometimes instead of black screen it shows some previously loaded screen
This is the code used to remove all the view controller from stack -
UIViewController *vc = self.presentingViewController;
while (vc.presentingViewController) {
vc = vc.presentingViewController;
}
[vc dismissViewControllerAnimated:YES completion:nil];
But still i can see some random screen from the app, comes up instead of black screen before my webview loads.
Any suggestions are welcomed. Thanks!!
Set in InterfaceBuilder or code white background color for UIWebView.
This code may help you:
- (void)viewDidLoad {
[super viewDidLoad];
webViewInstance.opaque = NO;
webViewInstance.backgroundColor = [UIColor clearColor];
//your remaining code here
}

How to remove navigation subview when view disapper?

I am using custom navigation view for navigation bar.
CustomNavigation *navigation = [[CustomNavigation alloc] initWithNibName:#"CustomNavigation" bundle:nil];
[self.navigationController.navigationBar addSubview:navigation.view];
This is my code for custom navigation to addsubview for navigation. I am using in viewwillapper. Because it's show and hide image and button based from popviewcontroller.
Here my problem is I need to dealloc this customnavigation view but I am already tried in view disappear it won't work? :( (I am using find that issue by "debug view hierarchy" in Hide or show debug area )
Am I using correct way for custom navigation bar or else give me correct way to create customized navigation bar?
If this is correct way to create customized navigation bar then how to dealloc this custom navigation view when view disapper?
I am new bee for xcode so give some little more explanation maybe I am struggles to understand. :(
Sample APP navigation only one at home screen also pop from another view
Sample APP at second view
My app at home screen
After few view my home screen navigation
Check all screens you will understand what I want.
I want to dealloc all navigation bar allocation form manually.
Screen shot's from "debug view hierarchy" in Hide or show debug area - XCODE.
This is worked for me :)
Add a tag for that view each time when I use add subview code before
for(UIView *view in [self.navigationController.navigationBar subviews])
{
if(view.tag == 1000 && [view isKindOfClass:[UIView class]])
{
navigation = nil;
[view removeFromSuperview];
}
}
If it's not perfect answer then show the correct one. Advance thanks.

Controls are not displaying in simulator when moving from one viewcontroller to other viewcontroller with navigationcontroller

I placed embedded Navigationcontroller at start of my mainViewController(Login) and added other viewcontroller(Home). In Login View controller i have a button so when i click on the button it should move to HomeViewcontroller, for this i have written Code in button click.It was redirecting to HomeView but having some issues
1)simulator was displaying as black page,if i set background color to white it was displaying as white
2)labels,textboxes etc any other fields which was drag and dropped to my home view was not displaying.but if i write code to generate the label or textbox i was displaying.
I have Added the constraints to my label(ex: welcome) but also the label wasn't displaying ,not only label any other static fields are not displaying but if i generate through code for any label or textbox it was displaying.
when i remove navigationController there are no issues.
hope i will get an answer to my Question.please help me in this issue. Thanks in Advance
For Buttonclick i have written the code as below and in HomeviewController i have drag and dropped the label,textbox,button but none of these was displaying
(IBAction)btnLogin:(id)sender {
HomeViewController *destinationController = [[HomeViewController alloc] init];
[self.navigationController pushViewController:destinationController animated:NO];
}
i was redirecting to homeView but was displaying as blackscreen and i changed the background as white then white screen was appeared but controls was not found

TabBar remains hidden despite setting tabbar.hidden = NO in controller

I currently have two view controllers, a CameraViewController that uses the imagePicker to take photos, and a PhotoInboxViewController that shows all the photo messages a person has received. PhotoInboxViewController, as well as my root view controller, is a Tab Bar Controller.
When I present the imagePicker in CameraViewController , as well as the image preview screen that follows it, I disable the TabBar by setting self.tabBarController.tabBar.hidden = YES. My issue is, when PhotoInboxViewController is then shown again (for example, if the user cancels taking a photo), I would want the Tab Bar to be shown again. In my viewWillAppear method in I have the following:
//In PhotoInboxViewController
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
if ([[[self tabBarController] tabBar] isHidden]){
self.tabBarController.tabBar.hidden = NO;
}
}
In debugging, I see that the if statement is indeed evaluated as tabBar as isHidden, and therefore the next line is executed as well. However, my Tab Bar remains hidden.
What am I doing incorrectly? Your help is appreciated - thanks!
You shouldn't need to hide the tab bar. When presenting modally you should present from the full screen / root view controller. In this case the tab bar controller, not the view controller 'in' one of the tabs. This allows the presentation to work properly without any strange side effects.

Display UIViewController as Popup in iPhone

Since there is no complete, definitive answer to this common recurring question, I'll ask and answer it here.
Often we need to present a UIViewController such that it doesn't cover full screen, as in the picture below.
Apple provides several similar UIViewController, such as UIAlertView, Twitter or Facebook share view controller, etc..
How can we achieve this effect for a custom controller?
NOTE : This solution is broken in iOS 8. I will post new solution ASAP.
I am going to answer here using storyboard but it is also possible without storyboard.
Init: Create two UIViewController in storyboard.
lets say FirstViewController which is normal and SecondViewController which will be the popup.
Modal Segue: Put UIButton in FirstViewController and create a segue on this UIButton to SecondViewController as modal segue.
Make Transparent: Now select UIView (UIView Which is created by default with UIViewController) of SecondViewController and change its background color to clear color.
Make background Dim: Add an UIImageView in SecondViewController which covers whole screen and sets its image to some dimmed semi transparent image. You can get a sample from here : UIAlertView Background Image
Display Design: Now add an UIView and make any kind of design you want to show. Here is a screenshot of my storyboard
Here I have add segue on login button which open SecondViewController as popup to ask username and password
Important: Now that main step. We want that SecondViewController doesn't hide FirstViewController completely. We have set clear color but this is not enough. By default it adds black behind model presentation so we have to add one line of code in viewDidLoad of FirstViewController. You can add it at another place also but it should run before segue.
[self setModalPresentationStyle:UIModalPresentationCurrentContext];
Dismiss: When to dismiss depends on your use case. This is a modal presentation so to dismiss we do what we do for modal presentation:
[self dismissViewControllerAnimated:YES completion:Nil];
Thats all.....
Any kind of suggestion and comment are welcome.
Demo :
You can get demo source project from Here : Popup Demo
NEW : Someone have done very nice job on this concept : MZFormSheetController
New : I found one more code to get this kind of function : KLCPopup
iOS 8 Update : I made this method to work with both iOS 7 and iOS 8
+ (void)setPresentationStyleForSelfController:(UIViewController *)selfController presentingController:(UIViewController *)presentingController
{
if (iOSVersion >= 8.0)
{
presentingController.providesPresentationContextTransitionStyle = YES;
presentingController.definesPresentationContext = YES;
[presentingController setModalPresentationStyle:UIModalPresentationOverCurrentContext];
}
else
{
[selfController setModalPresentationStyle:UIModalPresentationCurrentContext];
[selfController.navigationController setModalPresentationStyle:UIModalPresentationCurrentContext];
}
}
Can use this method inside prepareForSegue deligate like this
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
PopUpViewController *popup = segue.destinationViewController;
[self setPresentationStyleForSelfController:self presentingController:popup]
}
Modal Popups in Interface Builder (Storyboards)
Step 1
On the ViewController you want as your modal popup, make the background color of the root UIView clear.
Tip: Do not use the root UIView as your popup. Add a new UIView that is smaller to be your popup.
Step 2
Create a Segue to the ViewController that has your popup. Select "Present Modally".
Two Methods To Create Popup From Here
Method One - Using the Segue
Select the Segue and change Presentation to "Over Current Context":
Method Two - Using the View Controller
Select the ViewController Scene that is your popup. In Attributes Inspector, under View Controller section, set Presentation to "Over Current Context":
Either method will work. That should do it!
You can do this in Interface Builder.
For the view you wish to present modally set its outermost view background to transparent
Control + click and drag from the host view controller to the modal view controller
Select present modally
Click on the newly created segue and in the Attribute Inspector (on the right) set "Presentation" to "Over Current Context"
Feel free to use my form sheet controller MZFormSheetControllerfor iPhone, in example project there are many examples on how to present modal view controller which will not cover full window and has many presentation/transition styles.
You can also try newest version of MZFormSheetController which is called MZFormSheetPresentationController and have a lot of more features.
You can use EzPopup (https://github.com/huynguyencong/EzPopup), it is a Swift pod and very easy to use:
// init YourViewController
let contentVC = ...
// Init popup view controller with content is your content view controller
let popupVC = PopupViewController(contentController: contentVC, popupWidth: 100, popupHeight: 200)
// show it by call present(_ , animated:) method from a current UIViewController
present(popupVC, animated: true)
Imao put UIImageView on background is not the best idea . In my case i added on controller view other 2 views . First view has [UIColor clearColor] on background, second - color which u want to be transparent (grey in my case).Note that order is important.Then for second view set alpha 0.5(alpha >=0 <=1).Added this to lines in prepareForSegue
infoVC.providesPresentationContextTransitionStyle = YES;
infoVC.definesPresentationContext = YES;
And thats all.
Swift 4:
To add an overlay, or the popup view
You can also use the Container View with which you get a free View Controller ( you get the Container View from the usual object palette/library)
Steps:
Have a View (ViewForContainer in the pic) that holds this Container View, to dim it when the contents of Container View are displayed. Connect the outlet inside the first View Controller
Hide this View when 1st VC loads
Unhide when Button is clicked
To dim this View when the Container View content is displayed, set the Views Background to Black and opacity to 30%
You will get this effect when you click on the Button
You can do this to add any other subview to the view controller.
First set the status bar to None for the ViewController which you want to add as subview so that you can resize to whatever you want. Then create a button in Present View controller and a method for button click. In the method:
- (IBAction)btnLogin:(id)sender {
SubView *sub = [[SubView alloc] initWithNibName:#"SubView" bundle:nil];
sub.view.frame = CGRectMake(20, 100, sub.view.frame.size.width, sub.view.frame.size.height);
[self.view addSubview:sub.view];
}
Hope this helps, feel free to ask if any queries...

Resources