Problems when loading another UIView - iphone

In my app, I implemented a QR code reader that directs the app user to another View in the app after scanning any QR code.
I have two Xibs. One is the main screen that loads up when opening the app called demoViewController. The other is the page the app takes you to after scanning a QR code, called yViewController.
On yViewController, I masked the entire page using a UIView called sPage. The reason why I created this UIView is because I needed to implement this code:
[[NSBundle mainBundle] loadNibNamed:#"yViewController" owner:self options:nil];
[self.view addSubview:sPage];
Thats code that takes the user to the second page after scanning. I needed the mask UIView sPage in order to make this method work. And it does work.
However, I think this is screwing up my interface. I had a UIImageView in my sPage View implemented via the
demoViewConroller.m using viewDidLoad:
[topImage setImage: [UIImage imageNamed:#"ylogoREAL.png"]];
The image does not show up.
Additionally, I have some code to animate my view when the keyboard comes up and hides a textfield. This also does not work.
I know the hierarchy is right, because I use a buttonPressed method that works on the sPage View, as well as a method that closes the keyboard when touching the view. But nothing else works.
Can anyone help me figure out why? Im so confused :(

If I understand your error correctly you are calling a function and then ending the line with a semi-colon (programmers force of habit) then going to the next line (maybe) to open the function with a curly bracket.
-(void) function();
{
It needs to not have the semicolon
-(void) function()
{

I'm a bit confused as to what you're trying to achieve, but I'll give it a go
How do you initialize yViewController? I believe you should be using
yViewController = [[UIViewController alloc] initWithNibName:#"yViewController" bundle:[NSBundle mainBundle]];
instead of creating that mask view which loads up yViewController's nib.
Update:
After looking at your code, I believe you want to show a survey page after scanning is done. There are two things you can do
Option 1 - Easier
Present a UIView to the user, using your existing UIViewController (yViewController)
NSArray *nibs = [[NSBundle mainBundle] loadNibNamed:#"Survey" owner:self options:nil];
UIView *view_to_show = [nibs objectAtIndex:0];
[self.view addSubview:view_to_show];
Bear in mind that to be able to dismiss this view later, you will need a reference to it (declare it as a property) and later you can just do [view_to_show setHidden:YES]; or removeFromSuperview
Option 2 - UIViewController option
Create a new UIViewController with your survey view and show that
UIViewController *vc_new = [[UIViewController alloc] initWithNibName:#"Survey" bundle:[NSBundle mainBundle]];
[self presentViewController:vc_new animated:YES completion:nil];

All I needed to do was declare the topImage right under [[NSBundle mainBundle] loadNibNamed:#"yViewController" owner:self options:nil]; . I guess ViewDidLoad was the wrong place to put it in this case!

Related

SLComposeViewController Views sent to back in app and becomes unresponsive

I have a button in my app to bring up an SLComposeViewController for use with Twitter. When the view is presented it animates in correctly and the disappears. I have found that when it disappears it is sent to the back of the current view and I have no way to bring it back. I have tried manually sending all the views on top to the back in code with no luck. I feel there is something fundamentally wrong with my app for this to happen as this behaviour is seen at any level to the Navigation Controller in the app. Below is a screenshot of the SLComposeViewController being the Navigation Bar in the app, I made the ViewController's view have an Alpha value of 0.0f to illustrate my point:
I really don't know what is going on here and any help will be greatly appreciated. The code I am using to present the SLComposeViewController is pretty standard and I have tested it in another app and works fine:
NSString *message = [NSString stringWithFormat:#"#%#", [twitterInfo objectForKey:#"hashtag"]];
if ([appDelegate isSocialAvailable]) {
// code to tweet with SLComposeViewController
SLComposeViewController *twitter = [[SLComposeViewController alloc] init];
twitter = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[twitter setInitialText:[NSString stringWithFormat: #"%#", message]];
[self presentViewController:twitter animated:YES completion:nil];
}
Thanks for posting this, I had the same thing happen because I was adding a CAShapeLayer to my window for a gradient effect. Your post helped me figure out that this was the problem.
It looks like this is happening is because they are adding their view's layer to the window's sublayers--at index 0 I might add! This is contrary to what you would expect, which is that they would add their view as a subview to the presenting view controller's view.
They must have just thought that people don't add layers to their window and they want to make sure they are not competing with your view stack. Why they would put it into index 0 must only be because someone is in the habit of doing -[CALayer insertLayer:layer atIndex:0] I suppose.
I'm not certain but I am guessing this could be the case with any modal view controller.
The fix is pretty simple:
[viewController presentViewController:facebookViewController
animated:YES
completion:^{
facebookViewController.view.layer.zPosition = 1000;
}];
After a week of tearing my hair out to find a solution to this I have found the offending code in the app, a little trick to round the corners of the whole app, well make it seem like the corners are rounded by adding an image there:
UIImage *bottomOverlayImage = [UIImage imageNamed:#"bottom_overlay.png"];
CALayer *bottomOverlay = [CALayer layer];
bottomOverlay.frame = CGRectMake(0, self.window.frame.size.height - 9, bottomOverlayImage.size.width, bottomOverlayImage.size.height);
bottomOverlay.contents = (id)bottomOverlayImage.CGImage;
bottomOverlay.zPosition = 1;
[self.window.layer addSublayer:bottomOverlay];
If anybody could tell me why this code would mess up the Twitter View that would be really helpful for future reference. This code was placed in the app delegate and run on first load.

What exactly is done to a UIView on interface rotation?

could someone explain what iOS does on rotation of the interface. I´ve got a layout problem with one View that is gone after rotating the iPhone. Seems that the View got set a new frame, bounds or whatever, don´t know. Anyhow after the interface was rotated once the layoutproblem is gone forever. So something must be set to the view at the time the interface rotates.
I´m loading the View from a NIB file and show it with a navigationcontroller:
BirthdayReminderWidgetConfigViewController *vc = [self.storyboard
instantiateViewControllerWithIdentifier:#"BirthdayConfigController"];
self.navigationController pushViewController:vc animated:true];
Maybe there is some setting I have to do in order to show up the view correct without rotating the interface.
I´ve got a layout problem with a view that is loaded from a nib file as follows:
The project contains a MainStoryboard. Within that, I load a view from a nib file.
NSArray *xib = [[NSBundle mainBundle] loadNibNamed:#"View" owner:self options:nil];
self.configViewController = [xib objectAtIndex:0];
The storyboard has a navigation controller and the loaded view is shown like this:
if (currentWidgetConfigViewController != nil)
{
[self.navigationController pushViewController:currentWidgetConfigViewController animated:true];
}
So in my opinion nothing wrong? (First question)
But now the problem.
What I designed is that:
What iOS does is the following
The controls are not arranged well.
And besides that with a button on the new view I open up a PeoplePicker with that code:
[self presentViewController:self.picker animated:YES completion:nil];
After closing the People picker with [self.picker dismissViewControllerAnimated:true completion:nil]; I get this result:
So what is going wrong here?
Override -setFrame: and -setBounds: in your view to see what happens:
- (void) setFrame: (CGRect) newFrame
{
NSLog(#"New frame: %#", NSStringFromCGRect(newFrame));
[super setFrame:newFrame];
}
Also, the transform usually changes during a rotation. Orientation Zoo might help, it’s a sample Xcode project showing what happens in various rotation use cases. Didn’t touch it for a long time, though, so I don’t know if it still works.

Reuse UIControl subclass with the design made in IB

I have subclassed UIControl to create my custom control, but I have designed it using Interface Builder. Now I want to "export" it and use it for another application and I don't know exactly what I should do in order to be able to reuse it. It loads using initWithCoder.
I have searched quite a bit on the Internet, but I haven't find a right answer for my question.
Thank you.
Maybe you need use the following code in viewDidLoad of ViewController method:
CustomControl *control = [[[NSBundle mainBundle] loadNibNamed:#"CustomControl" owner:nil options:nil] objectAtIndex:0];
control.frame = CGRectMake(5.0f, 0.0f, 310.0f, 180.0f);
[self.view addSubview:control];

UIWebView content doesn't load until after view is shown

I have a UIView which, on viewDidLoad creates and shows a UIWebView. The web view doesn't actually show its contents until the view has actually appeared though. The navigation bar appears with the view during its animation process but the web view is populated a second after the animation has finished. How can I make the web view load the contents BEFORE animation begins. Here is my code, thanks:
-(void)viewDidLoad
{
[super viewDidLoad];
self.title = #"Help";
NSString *html = #"my html contents goes here, all local and all within a string - does contain one BG image though";
UIWebView *webView = [[UIWebView alloc] initWithFrame:_webFrame];
NSString *path = [[NSBundle mainBundle] bundlePath];
NSURL *baseURL = [NSURL fileURLWithpath:path];
[webView loadHTMLString:html baseURL:baseURL];
[self.view addSubView:webView];
[webView release];
}
I think a UIWebView needs some time to initialize, since it uses the WebKit engine.
You could try adding a simple timeout before actually pushing the new viewcontroller or show a placeholder during the 'push' animation.
As far as I know, a UIWebView has to be on screen in order to load and render.
i'd try the following:
create and add web view on the calling view controller.
set frame of the web view in a way only one pixel is shown on screen.
load html content.
push to new ViewController, remove Web View from old parent and add to new one.
might work, but it's really not worth the hassle, why not try to "solve" the issue by adding a load indicator or a placeholder text?

How can I prevent delayed display of my UIWebView

I must include some 'rich text' instructions* preceding a form; and thought adding a UIWebView to the header of the tableview would work. The HTML is a small file in my resources folder, the CSS is in a style tag in the file; so it's all nice and self contained.
The problem is, the view transitions in; then after a small delay the contents of the webview appear. The effect is jarring, and I don't think hiding the view and fading it in when it's ready would be any more desirable.
I'm creating the view with the code below, in my viewDidLoad method.
UIWebView * wv = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, HEADER_HEIGHT)];
[wv setBackgroundColor:[UIColor clearColor]];
[wv setOpaque:NO];
NSString *path = [[NSBundle mainBundle] pathForResource:#"HeaderMsg" ofType:#"html"];
assert(path != nil);
NSData *htmlData = [NSData dataWithContentsOfFile:path];
[wv loadData:htmlData MIMEType:#"text/html" textEncodingName:#"utf-8" baseURL:nil];
[self.tableView setTableHeaderView:wv];
[wv release];
I found 2 ugly workarounds, but I'm hoping someone has a better solution; since my workarounds make a real mess out of the code:
On previous screen when you make the
UIMYSCREENViewController, call a
[vc
preloadWebViewWithDelegate:self];
method which will make the webview
using the caller as the delegate.
The caller then retains the vc and
waits for the webview to sent it a
webviewDidFinishLoad method, at
which time it can present the view
and release the vc.
The calling view can make the webview,
wait for it to finish, then create the
new view and pass the webview into it.
At any rate, both of those "solutions" make me gag a little, so I'm hoping others have found a better way.
(*The instructions are mostly simple, styled text with some bullet points (no images or overly aggressive styling); but it takes about 14 carefully aligned UILabel views to simulate this without a webview - and is subject to the whims of the customer wanting to change the message.)
I would create another independent model or controller object to create and retain the webview, hopefully at a higher level and before (maybe during app init) displaying the view with the UI that could bring up the webview.
Consider this the same as pre-staging resources for an action game so that they don't have to be loaded during the game loop, which is a common design pattern.
Consider using this
https://github.com/Cocoanetics/DTCoreText/