Just a quick question.
I am busy with an iPhone app based on the Utility Application template to set me up with the Core Data info.
I was just wondering, why the FlipViewController is set up the way that it is.
Is it not much easier to do link in storyboard with a modalview segue a
- (IBAction)doneFlip:(id)sender
{
[self dismissModalViewControllerAnimated:YES];
}
To return to the previous view?
Is this a performance reason?
Cheers
Apple's templates are always a mess in Xcode 4.x. For those who can remember way back to Xcode 2.x or even early 3.x, the templates were relatively uniform with excellent comments and very little extra gruff in the way. But in 4.x, the templates have become a jarring mix of coding styles, preferences, and traditions from Apple's many Xcode developers.
As for that:
- (IBAction)doneFlip:(id)sender
{
[self dismissModalViewControllerAnimated:YES];
}
-dismissModalViewController would not be the best thing to use (it should be called from the presenting controller. Use -popViewControllerAnimated instead if it is in an action from inside the presented view.
Related
I created a new project "Single View Application" and designed the mainView with Storyboard. My main view contains a UIButton that opens the camera, the camera scans barcode and automatically goes to a website. Now I created a webView programmatically so that website can open and also created a UIButton inside the webView. Now I want that UIButton to act as home botton and return to mainview. I am unable to do that, please help.
ViewController.m code: http://cl.ly/FKj8
My storyboard looks like:
You really should look into the View Controller Programming Guide -- by switching around the contents of a single view controller, you're making a lot of extra work for yourself with little benefit. By using multiple view controllers when you want to have different "screens" in your app, you can take advantage of storyboarding for easier development, and you automatically get better memory management (read: less potential for crashes), too.
However, to more directly answer your question... if you're putting the WebView into the view hierarchy with [self.view addSubview:webView], you can remove it with [webView removeFromSuperview]. (This means you'll have to keep a reference to the WebView around so you can refer to it when you want to dismiss it.)
I also noticed in the code you posted to cl.ly an unrelated method -deviceModel which uses uname() to get device information. This is a bad idea, for two reasons:
uname() isn't guaranteed to do something useful on an iOS device (even if it currently does). Use the UIDevice class instead if you need this kind of info, or...
Generally, you don't want to test for the device name to enable functionality in your app; instead, you should test for the capabilities you need. (For example, if you look for a device name starting with "iPhone 4" to test for a Retina display, you'll miss the 4th-generation iPod touch, and the iPhone-5-or-whatever-they-call-what's-next. Instead, use the UIScreen class.)
I have a nice little app on the app store that does pretty well for itself. Life was great until iOS 5 came to town. Now, I have a number of issues with my app that I have no way of fixing because I have no clue what is going on, because I feel that they are iOS 5 issues, not mine.
Was there an iOS 5 conversion manual I missed? Or did they just change everything for fun, and want us to figure out where all the easter eggs were?
Here is another issue I am experiencing (that I have wasted so much time trying to fix), that DON'T EXIST AT ALL when I simply say that I want to run the app in good ol' 4.2:
Modal view
My app is a simple reader app. I have a book reading view that displays text with a UIWebView. One of the features I have been working on involves the ability to take notes as you read. This is achieved by hitting a button, and presenting a modal view. Yes, a modal view. The most simple pre- iOS 5 thing you could possibly do. Now, when I dismiss my modal view, just by hitting cancel, and simply dismiss the view, when I get back to my reader view, the navigation bar at the top is pushed up half way off the screen! This doesn't happen in 4.2, but there it is in iOS 5!
What can I do to get this issue resolved?
Thanks for your help.
Ok, I was just able to figure out what in the blazes was going on. I had the shouldAutorotateToInterfaceOrientation value set to a BOOL variable, so that when the modalView was coming back, it didn't know the state/size of the status bar. Fixed that, and the problem disappeared.
I have the feeling it has something to do with the way you present and dismissing the modalview. Apple introduced a new method to present views. May you try using theses instead of the old ones and see if it fixes your problem.
So here is what you do:
change this method:
presentModalViewController:animated:
into the new preferred method introduced with iOS 5:
presentViewController:animated:completion:
Depending if you are using dismissModalViewControllerAnimated:to dismiss your view, change it into dismissViewControllerAnimated:completion.
This methods also have completion handler which is very useful to do some extra work after the view has been presented/dismissed. Maybe that also helps with your other issue. Let me know if that might helped.
A major change in iOS 5 is that the navigationController property of UIViewController is no longer set for modal views. Instead, there is a new (not present in iOS 4) parentViewController property. So where you're using navigationController in a modal view you need to change the logic to something like:
UIViewController* parent;
if ([self respondsToSelector:#selector(parentViewController)]) {
parent = self.parentViewController;
}
else {
parent = self.navigationController;
}
(That's from memory, so I can't guarantee that every t is dotted and every i crossed.)
I was seeing this same clipping problem.
I found out that the reason for my issue was that I set the content size within the modal dialog (something I did for my iPad layout), so removing these two lines seemed to fix the issue:
CGSize size = CGSizeMake(320, 480);
self.contentSizeForViewInPopover = size;
I thought the problem was fixed but it wasn't. After reviewing the code some more, cleaning the build, and retesting it turned out to be a shouldAutorotateToInterfaceOrientation which would return NO for all orientations, for a brief amount of time (flag == NO) while the app is loading (root controller). You want to at least return YES to one orientation like so:
- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
return !self.flag ? UIInterfaceOrientationPortrait == toInterfaceOrientation : YES;
}
I'm wanting to make a multiview app with 5-6 different screens and a data source to store user information. I've never made a multiview app before, and I have a good idea on how to start, but I'd like to hear some recommendations on "structuring" your app to properly support this.
A very simple analogy could be going about making a background color on a website... You could either use an image of a solid color or simply use the background-color style. Both get the job done, but using the style is a bit easier/more efficient.
I just want to make sure I'm starting off on the right foot. Should I keep all my functions in one class' .m/.h file? What's the best/efficient way to go about different screens?
Thanks, and I'll definitely try to help others out once I get a much better grasp on Objective-C and Xcode.
If you are new to the iPhone/iPad I highly recommend you check out the CS193P lectures, they are also avaliale on itunes. They give a good overview of iPhone programing and how things are done in Objective-C / Cocoa Touch. It will get anyone started in the right direction.
As to your specific question. Just start coding. In 6 months you'll realize eveything you wrote is cr*p and needs to be rewritten anyways, but doing it is the only way you'll realize what you wrote is cr*p so...
Some suggestions, specific to multi-viewed apps (which almost every app is) and I'm sure someone else can expand on this...
Learn (as much as possible) to code interactions between different views and viewcontrollers (vs using interface builder). The twitter app for example doesn't use Interface Builder at all.
If you use IB, don't dump everything into one .xib. Learn how to break them up. One .xib per viewcontroller should be it. I never use the IB UITabBarController or IB UINavigationController, those get initilized and used in code only.
Absolutly learn MVC (Model view controller).
The Apple documentation is often a good place to start for most things. Try here first. Hope this helps and good luck!
I used to use a UINavigationController. I created it as a singleton and accessed it statically so I could push and pop controllers easily (theres a reasonably good tutorial here). This is quite lightweight and theres enough documentation to get going with it quickly.
However the best approach I've used is the Three20 framework's TTNavigator. In a nutshell its a beefed up UINavigator that lets you push a new view onto the screen by calling an internal URL:
//(In your app delegate)
//Start up the navigator
TTNavigator* navigator = [TTNavigator navigator];
navigator.persistenceMode = TTNavigatorPersistenceModeTop;
//Map url's to controllers
TTURLMap* map = navigator.URLMap;
[map from:#"*" toViewController:[TTWebController class]];
[map from:#"ac://search" toViewController:[SearchViewController class]];
[map from:#"ac://results/(initToView:)" toViewController:[ResultsViewController class]];
Then to navigate to a controller:
[[TTNavigator navigator] openURLAction:[[TTURLAction actionWithURLPath:#"ac://results/searchResults/"] applyAnimated:YES]];
Whats also cool is that calling that #"ac://results/" the way we have above passes in the param #"searchResults" to the init method of the ResultsViewController ("initToView:") as we defined in the mapper
All the best!
Before I implement something similar for the iPhone, I'm wondering if anyone has implemented something similar of the UIPopOverController for the iPhone. This is so far only available for iPad.
See my implementation here: https://github.com/werner77/WEPopover
It has the same interface as the UIPopoverController but is generalized for iPhone and with support for custom background views.
I have provided another alternative SGPopoverController at http://github.com/KJoyner/SeaGlass. Like the WEPopover, this has a similar interface to UIPovoerController but works on the iPhone. This version handles more corner cases, works both modally and non-modally, supports passthrough views, and more.
Create
UIPopover+iPhone.h
#import <Foundation/Foundation.h>
#interface UIPopoverController (overrides)
+ (BOOL)_popoversDisabled;
#end
There's a reason UIPopoverController isn't a standard UI element on the iPhone, is that screen space is rather restricted. Having a popover, that's easily readable, implies that a fair amount of the iPhone screen will be taken up by the popover. Perhaps you should rethink your UI decision.
Maybe a coverVertical modal view?
Found another git. Looks more updated and actively maintained. it uses QuantzCore to draw the popover, which looks as elegant as iOS's SDK native.
Just for your reference: https://github.com/50pixels/FPPopover
Basically the best way to do this is to implement custom UIAlertView subclasses that look/behave how you want, via custom animations and being able to click behind and disappear (if you want that functionality, as UIPopoverController has it)
Edit: you can also try using a view and presenting it modally, though the animations might not be what you are looking for.
i have problem with autorotate on iphone
i set up in all classes
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
but it is not respond ;/
Sample code is: http://b6.s3.p.quickshareit.com/files/testautorotatecb367.zip
problem is only with first tab, if i switch application to second tab, and rotate iphone, interface is rotating. it is not rotating in TAB1, where i put custom UINavigationController
OK
problem is that i do not init navigation views, i use only alloc, after i add alloc] init] all started works OK
Okay, i think i see what the problem is in you code. You need to add your UINavigationBar to the delegate like you did with the tab bar, otherwise it doesn't know of its existence and therefore it isn't rotating because it is confused on what is in the view.
Because I use Interface Builder to take care of all my GUI needs, i'm not sure how to do this manually in code, so, to help you out, here >> http://www.radford.edu/ebalci/Tutorials/SimpleTabNavTemplate.zip is a tutorial kind of thing i made a few days ago for a friend, you can use it as sort of a template or guide to help you out (i hope it will help you)
[my tutorial uses UItableViews for navigation but that is optional]
also, i commented out my rotation methods because i wasn't worried about it at the time, but
if you uncomment them (and i think you have to add the method to one of the classes because i deleted it) it will rotate, i just checked, but was too lazy to re zip it and upload it.
I just want you to know that I pretty much just made this thing a day ago, there is a rich text file in the zip that has instructions, but, it is a rough draft, i haven't really revised it yet so, i hope you can read through it with ease despite the fact it is a rough draft.
Let me know if it helps =) Good Luck
And your custom UINavigationController also has the same
shouldAutorotateToInterfaceOrientation
method that returns YES to landscape views?