UIview doesn't work property with viewdidappear [duplicate] - iphone

I have a tableview project which has a view, everything that I do in this view is controlled by "viewdidappear" method.
I added a new UIview which has "lines.h" and "lines.m" files.
I use this view to draw some lines and works god.
This extra view is located in to a scroll view because is to long to display in to iPhones screen.
The problem is that viewdidappear doesn't reload the uiview data, it only works with viewdidload.
I have to close the application and reopen it to get my data reload.

First, try adding this line at the end of viewDidAppear method:
[self.view setNeedsDisplay];
Or:
[_linesView setNeedsDisplay];
Second, Provide some more information. Post the code in viewDidLoad and viewDidAppear.

Try calling [self setNeedsDisplay] in the lines UIView class to cause the view to redraw itself.

Related

UIview doesn't load with viewdidappear

I have a tableview project which has a view, everything that I do in this view is controlled by "viewdidappear" method.
I added a new UIview which has "lines.h" and "lines.m" files.
I use this view to draw some lines and works god.
This extra view is located in to a scroll view because is to long to display in to iPhones screen.
The problem is that viewdidappear doesn't reload the uiview data, it only works with viewdidload.
I have to close the application and reopen it to get my data reload.
First, try adding this line at the end of viewDidAppear method:
[self.view setNeedsDisplay];
Or:
[_linesView setNeedsDisplay];
Second, Provide some more information. Post the code in viewDidLoad and viewDidAppear.
Try calling [self setNeedsDisplay] in the lines UIView class to cause the view to redraw itself.

strange loading / not loading viewController

When I use this line of code in the viewDidLoad of the app's main viewController, it is just getting completely ignored:
[self presentModalViewController:nextController animated:YES];
The nextControler doesn't load, nothing at all happens.
I do know the code is being "executed" since I put an NSLog before and after it and also ran through the program with a breakpoint.
When I call this line elsewhere in the code, it works perfectly as expected, but in viewDidLoad it is being ignored.
So I tried this code to see if there would be any difference:
[self.view addSubview:nextController.view];
This is loading the nextController view over top of my main view but some of it is transparent so that the main view shows through, and when I try to click on a button in the nextController, it is actually NSLog'ing as a press on a button in the main view below it.
Does anybody have any idea what might be happening here?
Thanks in advance!
viewDidLoad is called before the view controller is inserted into the view controller hierarchy. That's why it just doesn't know how to present a modal view controller at this point. Try moving the code into viewDidAppear:.

How to remove subview from Superview?

I have taken one subView of type UIView on the top of UIViewController. I want to remove it and again load it after clicking on button. But I am unable to remove it.
I have used [subView removeFromSuperview] method. But it is not working.
Try out the method inside the AppDelegate. If you have loaded the rootViewController.view as a subview to your window, try to unload it again, you should see a white screen.
[self.window addSubview:rootViewController.view];
[rootViewController.view removeFromSuperview];
Also, insert this line before you removeFromSuperview in your code:
NSLog(#"%#",[rootViewController.view superview]);
Replace rootViewController.view with your view. If the log reads (null), it means you have incorrectly assigned your view as a subview.

Trying to remove Super ViewController but stuck in View?

I have 3 ViewControllers 1.Main 2.Gallery 3.Text. What my problem is that i have the GalleryViewController using an External UIView with the name GalleryItemView. So once the view controller calls this inside the UIView i have a button that changes the subview so what i do is use the [super addSubView:newView]; eveything works out great but when i return to the GalleryViewController my app crashes so im guessing im doing this wrong. also what i notice is that once i change Views from pressing the button inside the GalleryViewController takes me to the menu and when i do a swipe gesture it scrolls horizontal and i do have a scrollview in the GalleryViewController Class so maybe what im doing is adding a subview to the ScrollView anyone know how i can fix this?
For starters:
[super addSubView:newView];
is pretty much incorrect.
Adding a view to a viewcontroller, you want to do
[self.view addSubview:galleryItemView];
[self.view bringSubviewToFront:galleryItemView];
If you believe you have added it properly, you could do the following to verify it:
if ([galleryItemView.superview isKindOfClass:[UIScrollView class]]){
NSLog(#"galleryItemView's parent is a scrollview");
}
Please post the crash if you still have problems.

iPhone - Have the keyboard slide into view from the right like when editing a note in Contacts

I'm looking for a way to slide the keyboard into view from the right, like what happens in the Contacts application when you edit a note.
My problem is that when I call [someTextView becomeFirstResponder] in viewWillAppear, the keyboard immediatly pops up with no animation. And when I call it in viewDidAppear, the view first slides in from the right (UINavigationController does the sliding), and then the keyboard slides in from the bottom.
Is it possible to have the keyboard slide in from the right, together with the view?
Solution
In iOS 7, calling becomeFirstResponder on _textView in viewDidLayoutSubviews works.
- (void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
[_textView becomeFirstResponder];
}
Note: Doing it in viewWillLayoutSubviews also works.
Explanation
Read the discussion in the docs for becomeFirstResponder.
You may call this method to make a responder object such as a view the first responder. However, you should only call it on that view if it is part of a view hierarchy. If the view’s window property holds a UIWindow object, it has been installed in a view hierarchy; if it returns nil, the view is detached from any hierarchy.
When using a navigation controller to push your custom view controller onscreen, self.view.window is still nil by the time either viewDidLoad or viewWillAppear: is called. So, _textView.window is also nil in the same methods, since _textView is a subview of self.view, i.e., they're both in the same window. No matter how you present your custom view controller, self.view.window (and thus _textView.window) is also nil in initWithNibName:bundle:. self.view.window is set by the time viewDidAppear: is called, but that's too late because by that time, the navigation controller has already completed the animation of pushing the view onscreen.
self.view.window is also set by the time either viewWillLayoutSubviews or viewDidLayoutSubviews is called and these methods are called before the push animation of the navigation controller begins. So, that's why it works when you do it in either of those methods.
Unfortunately, viewWillLayoutSubviews and viewDidLayoutSubviews get called a lot more than just on the initial navigation controller push. But, navigationController:willShowViewController: and willMoveToParentViewController: get called too soon (after viewDidLoad but before self.view.window is set) and navigationController:didShowViewController: and didMoveToParentViewController: get called too late (after the push animation).
The only other way I can think of doing it is to somehow observe the window property of _textView so that you get notified when it changes, but I'm not sure how to do that since window is readonly.
All you need to do is tell the text view in question to become the first responder in the viewDidLoad method of the view controller you're pushing onto the navigation stack:
override func viewDidLoad() {
super.viewDidLoad()
someTextView.becomeFirstResponder()
}
This works in iOS 8. The keyboard slides in from the right along with the view.
In iOS 7 (or any version before) you can make a simple thing in loadView, viewDidLoad or viewWillAppear
[yourTextView performSelector:#selector(becomeFirstResponder) withObject:nil afterDelay:0.0];
In this case you will get left-to-right appearance of the keyboard aligned with the motion of pushing view controller.
For iOS 7 I've found the following solution to work the best for me:
-Import UIResponder-KeyboardCache to your project.
-Add [UIResponder cacheKeyboard:YES]; to the viewDidLoad of the view before the keyboard view. It might be better to do this immediately when the application loads or during a time convenient when you can afford it (during an HTTP request, for example). In most cases, simply in the view before is sufficient.
-Add the following to the viewDidLoad of the keyboard view.
dispatch_async(dispatch_get_main_queue(), ^{
[_textField becomeFirstResponder];
});
To explain, this will preload the keyboard view, which will remove the delay from the first call of the keyboard view. Calling becomeFirstResponder on the text field in the main queue causes it to slide in with the view instead of animating upward before the view slides in.
You could try sending the becomeFirstResponder message to the new view controller before you push it onto the stack. For example:
-(void)functionWhereYouPushTheNewViewController {
yourNewViewController *newVC = [[yourNewViewController alloc] init];
[newVC.yourTextView becomeFirstResponder];
[self.navigationController pushViewController:newVC animated:YES];
}
I have found that changing animations on things like they keyboard is pretty tough though, and if you read the Human Interface Guidelines Apple makes it pretty clear that they want certain things to act in certain ways, all the time. There are ways to change the behaviors of certain animations but they often involve undocumented API calls and are grounds for rejection from the app store. It would be a violation of HIG to have pushed views slide up from the bottom, for example.
Hope this helps.