With the storyboards, it is really easy to presentModalViewController but I didn't find a way to dismissModalViewController. Is there a way to do it ? Or do I need to do it through the code ?
Thank you.
In iOS 5 the preferred new way to do this is to use the more powerful
- (void)dismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))completion
Related
Recently tried to implement a toolbar in my app, for now I'm using the uitabcontroller which is built in.
I wondered if it was possible to edit something like so:
http://i64.tinypic.com/iwlxzo.jpg
I've failed to find any documentation on customising a uitabcontroller or creating one...
Thank you in advance!
You'll need to subclass UITabbarController to perform the changes that you require. I suggest you look up subclassing to get the right idea.
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.
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'm developing a simple tab bar application for school.
It has 3 tabs.
One of them plays music in streaming and I would like to stop the music playing when the user changes the tab. Is this possible? and How? Thank you in advance!
Implement the UITabViewController delegate method:
– tabBarController:didSelectViewController:
And you should be able to do what you want. There's also
– tabBarController:shouldSelectViewController:
if you want to know before the tab changes.
As Carl says, this is possible. However, if I were to develop such application (and actually, I am), I would use the viewWillDisappear method of my UIViewController (and I am). That way you keep the logic separated between your implementations.