As per the tags indicate I'm developing in Xcode for the iPad.
So, I have a New Game setup screen that sits between my main menu screen and the actual game screen. The new game setup screen is supposed to allow the user to customize their game by selecting the number of players, choosing an avatar for each and setting their names. What I've done is I've setup the continue button to write all the settings to a appData.plist file before moving onto the actual game screen. When the game screen appears (the viewDidLoad method) it reads from the plist to add the players to the table with their respective Avatars and so forth.
The question is, is this the right way to pass the data from a new game setup screen to the game screen? Should I use some method to gather the information from the screen and pass it along to the game screen without writting to some file? I guess the ultimate question is how you're supposed to pass data from one view controller to another? I'm using some plist file to write to and then read from when the board appears. I get a sneaking suspicion that this is not the right way to do this. However, I figure at some point I need to save this data to file anyway since I have to be able to restore the state of my app in the even that it gets closed or interrupted. But what is YOUR preferred method to accomplish this?
You can always use the built-in settings screen for your app by making use of the Settings.bundle too. This is very easy and allows you to use the default iPad settings screen for your application settings, rather than setting up a hand-made one.
For passing through information, the information I need is usually a single object (in your case maybe Player.m) and so I create a property in the next view to hold this. And before showing the view I then do (for instance):
GameViewController *gameView = [[GameViewController alloc] initWithNibName:#"GameViewController" bundle:[NSBundle mainBundle]];
gameView.player = player;
[self.navigationController pushViewController:gameView animated:YES];
[gameView release];
Related
What would be the specific steps and code (aka, the simplest possible example) - as per best practices in Swift/Xcode - for developing a dynamic UI with the following "Hello World" implementation requirements?
Create a single view controller with a specific layout - let's say just 2 labels (First Name and State), and 2 buttons (Back and Next)
Be able to then reuse that layout as many times as necessary for a new/subsequent screen, that user can navigate to from where the user is currently at, and where the same layout components (Name and State) are updated with the content for the specific screen (in the sequence) that will be shown
Here's a screen shot of what that could like if the screens are hardcoded in the StoryBoard, where the next buttons are connected with Show Segues:
I am new to Swift/Xcode, coming from a background in Android development. Studying Swift, I have not so far run across much tutorials to implement this kind of UI/UX via a dynamic approach with a reusable layout definition. The tutorials I'm seeing seem to all require that every screen that is necessary, be explicitly added via the IDE StoryBoard
For a concrete/specific example of what I'm looking for, in Android the common way to solve for this is :
Create a Java class that extends Fragment, and a corresponding layout that has the 2 text labels and 2 buttons
For the fragment - define a constructor that takes 2 parameters: Name, State
Every time a new screen is needed, a new instance is generated where the contructor is called with the necessary Name and State parameters for the new view
The new instance is pushed onto the fragment manager instance, and that causes the new screen to load for the user
When user clicks Next (where next is possible), steps 3-4 are repeated for the new content
Use UINavigationController and hide navigation bar.
advantage: navigationcontroller could help you 'next' and 'back' view controllers easily.
it's a good way for your achieve.
Use ContainerView.
it's more like fragment in android.
Use uiview only.
it's simple and easily.
I am using storyboards in XCODE4.
I am currently able to launch a video from a table cell using a push segue from a tableview controller to a viewcontroller. When the segue gets called, the view controller immediately launches the video using standard media player code in viewdidload. My problem is once the video is over, the app doesn't return to the table cell, instead it stays at the blank table view controller until a user clicks "Back".
Anyone know a simple way to have the video end and switch back to the TableViewController?
Apple didn't make this one easy. My assumption is that they want the user to choose to exit the movie player when s/he feels comfortable enough to do it (and then the user would have the choice to replay or skip back to parts that they might want to see again).
But one way to catch the end of the movie happening would be to register for the "MPMoviePlayerPlaybackDidFinishNotification" notification (documentation linked for you) and then exit and/or remove the MPMoviePlayerController.
Note: this notification also fires if there's any error while loading the movie (see the documentation for initWithContentURL:).
How could I move a subview to the front of the stack when the LevelMeter detects a certain amount of decibels? I want LevelMetering to be active in real time without a record play function.
Ultimately, I'm trying to animate a mouth to open and close based on sound.
To make a view topmost in the view order, you just have to send a -bringSubviewToFront: to the view that contains it. From a view controller, you might do something like:
[self.view bringSubviewToFront:levelMeterView];
If that doesn't answer your question, perhaps you can expand a bit on what you're asking?
I'm trying to get a window I've created to accept files dropped onto it from the finder and all that happens when I try and drag a file onto the window is it snaps back to where it was on the desktop. Clearly I'm not setting something up right.
Inside the NSWindowController:initWithWindow: I'm doing:
[self.window registerForDraggedTypes:[NSArray arrayWithObjects:NSFilenamesPboardType, nil]];
I've tried putting this line in the view as well and no luck. What am I missing? Is there something I need to set in the .xib file as well?
Where do I need to put the -(BOOL)performDragOperation: function? Is that in my custom NSWindowController class? Is that what is failing?
Have you followed (or read) the documentation? The relevant section is titled "Receiving Drag Operations.
Most importantly, for a general view (or window), you need to implement -draggingEntered: as a first step and return the proper NSDragOperation (or at least not NSDragOperationNone) to "validate" the proposed drop. Without answering this, a drop won't even be allowed (so you'll never receive -prepareForDragOperation:, -performDragOperation: or -concludeDragOperation:).
Something else to consider: Do you really want the whole window to act as the dragging destination? More often, it's best to use a specific view that gives visual feedback to the user when -draggingUpdated: is called.
I have never made an app using XCode and Cocoa but I think following these instruction:
http://developer.apple.com/Mac/library/documentation/GraphicsImaging/Reference/IKImagePicker_Class/IKImagePicker_Reference.html
I could easily make an app that pops up a window that allows you to push a button to bring up the IKPictureTaker, but this is not quite what I want. I want my app to just automatically bring up the PictureTaker. I assume to do this I would have to abandon the interface builder altogether and do the whole thing programatically but I can't figure out what call will tell the Cocoa app to use this class or method at start up. Where would this be done programatically? I am trying to do all this in a Cocoa app that will be run in OSX.
alt text http://www.freeimagehosting.net/image.php?38f459584c.png][img=http://www.freeimagehosting.net/uploads/th.38f459584c.png
You'll want to use the beginPictureTakerWithDelegate:didEndSelector:contextInfo: method, which will give you a stand-alone pictureTaker window.
IKPictureTaker *sharedPictureTaker = [IKPictureTaker pictureTaker];
[sharedPictureTaker setValue:[NSNumber numberWithBool:YES] forKey:IKPictureTakerShowEffectsKey];
[sharedPictureTaker beginPictureTakerWithDelegate:self didEndSelector:#selector(pictureTakerDidEnd:returnCode:contextInfo:) contextInfo:nil];
If you put that somewhere, like in your Application Delegate's applicationDidFinishLaunching: method, you'll get the picture taker window # startup.
If you want a more custom solution you can look into the QuicktimeKit. It's not as easy as the three liner posted above but it's relatively pain-free. You'll have much more flexibility in the look of your picture taker window, be able to select from any number of inputs, be able to add your own filters, etc. Could be worth a look.
I'm not totally familiar with the IKPictureTaker. If it does something I'm not crediting it then let me know.
The way to automatically instantiate a class in Xcode /Cocoa is, strangely enough, through Interface Builder (IB). Open your MainMenu.xib in IB and make sure you can see the Document window (menu Window >> Document). Now, in the Library expand Cocoa >> Objects & Controllers >> Controllers. You'll see a number of controller, among them a blue cube. Drag this blue cube to your MainMenu.xib document window. You'll see that File's Owner and Font Manager sport the same blue cubes as their logo. Now, select your blue cube and in the Inspector choose the Identitiy panel (letter i on blue circle). Set the Class to the class you created before in Xcode, and save MainMenu.xib.
When you run your program, your class will automatically be instantiated. Your starting point from where you can start calling other methods or instantiating other objects is
- (void)awakeFromNib
{
NSLog(#"%# I'm alive!", [self class]);
}