I have a simple iphone app that's based on the CrashLanding sample app. So basically you tap the title screen and do some stuff... all on the same "view". I want to add an "options" screen/page/view whatever with a few UISwitches. What's the easiest way to do this?
Cheers!
There are numerous examples that show how to manage multiple full-screen views -- each view should typically be managed by a separate view controller. Check the Xcode templates for an example of how you can set up a "flip" view.
Dunno if this will help I'm a bit new to objective-c and iPhone api.
Maybe u can do something like this:
Use the interface builder: just type "Interface Builder" on the Spotlight (top right corner) to generate like "myOptions.xib"
And then just implement it: like
#implementation myOptions
-(void)awakeFromNib
{
...
You can take a look at the QuartzDemo under the iPhone API to see how to load the interface list of objects. In the previous view controller you just need to add it to the object list.
It will look something like this:
#implementation previousController
-(void)awakeFromNib
{
menuList = [[NSMutableArray alloc] init];
QuartzViewController *controller;
controller = [[QuartzViewController alloc] initWithTitle:#"Options"];
controller.quartzViewDelegate = [[[myOptions alloc] init] autorelease];
[menuList addObject:controller];
[controller release];
Hope it helps
Use the Interface Builder to open MainWindow.xib. Add a new View to the XIB. Refer to the Interface Builder User Guide for more details.
http://developer.apple.com/documentation/DeveloperTools/InterfaceBuilder-date.html#doclist
While everyone has mentioned ways and pointers for displaying an additional view, if you are trying to solve your original problem of displaying application settings, you may want to use a settings bundle instead as per the Apple HIG for the iPhone
http://developer.apple.com/iphone/library/documentation/UserExperience/Conceptual/MobileHIG/HandleTasks/chapter_6_section_4.html#//apple_ref/doc/uid/TP40006556-CH16-SW4
For how to do this, see this:
http://developer.apple.com/iphone/library/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/ApplicationSettings/chapter_12_section_1.html#//apple_ref/doc/uid/TP40007072-CH13-SW10
Related
I'm new to Objective-C and following Apple's tutorial on how to create a simple app with tableView and detailsView:
https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/SecondiOSAppTutorial/SecondiOSAppTutorial.pdf
I only differed from the instructions by using different names and embedding it into a tabbed app.
I compared my code twice to the one shown in the tutorial and it's the same...
I also searched the web for two days trying to find an answer to this problem. The only thing I found is that a lot of people had problems when trying to use dynamic prototype with storyboards, but, there usually weren't any answers, and if there were they didn't help in my case.
Another thing I found is that neither the viewDidLoad method or the awakeFromNib method are being called when the app loads or the view is shown. I saw other questions about it, but, with no answer.
Would HIGHLY appreciate your help!!
Thanks!
Shila
Relevant code:
Data controller initialization:
#interface MMMeetingDataController ()
-(void)initializeDefultDataList;
#end
#implementation MMMeetingDataController
-(void)initializeDefultDataList
{
NSMutableArray *meetingList = [[NSMutableArray alloc] init];
self.masterMeetingList = meetingList;
MMMeeting *meeting;
NSDate *today = [NSDate date];
meeting = [[MMMeeting alloc] initWithSubject:#"Default" invitees:#"Default" location:#"My Office" date:today];
[self addMeetingWithSubject:meeting];
}
TableViewController (list):
#implementation MMMeetingsListViewController
-(void)awakeFromNib
{
[super awakeFromNib];
self.dataController = [[MMMeetingDataController alloc] init];
}
-(void)viewDidLoad
{
[super viewDidLoad];
}
-- Both of the above functions are not being called in debug...
Open your storyboard, click on your view controller (the yellow circle icon under your table view should be selected, see the screenshot), and make sure the Custom Class field is set to the name of your view controller (MMMeetingsListViewController).
Problem solved. Since I was using the tabbed application and added the tableView controller manually, I should have also embedded it in a navigation bar. Once I embedded the tableView controller in a navigation bar problem was solved.
What I want to do is a navigation bar with a image on it. I have a tab controller on my main view, and inside each tab I have a UINavigationController. From inside the UIViewController that my tab/navigationController calls, I could set the titleView without much problem, doing this inside the viewDidLoad method:
self.navigationItem.titleView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:#"mylogo.png"]] autorelease];
But, I want to replace all titles in my navigationBar for this view, and it seems ugly to repeat this everywhere. So I did this on the delegate (after linking all the Outlet stuff)
self.tabOneNavController.navigationBar.topItem.titleView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:#"mylogo.png"]] autorelease];
Again, it worked! ok, I'm almost getting there.
But the point is, I've 5 tabs and all of them have navigationControllers inside. I reduced the code repetition from every internal view to only 5 times, but it still. It requires that I do that for the NavController of each tab.
Then I tried to extend the UINavigationBar to create my own, where I could set this in the initializer, and use it in the interface builder as the object class. But it doesn't seem to work. Here is what I did:
#implementation MyNavigationBar
- (id)init {
self = [super self];
self.tintColor = [UIColor greenColor];
self.topItem.title = #"testing please work";
return self;
}
#end
in the interface file MyNavigationBar inherits from UINavigationBar. But this didn't work. Should I overwrite other method? which one? is this a good practice?
I'm not even sure if I should add one navigationBar for each tab, as I said, I have tabs and I want to have a navigation bar / navigate inside them. By now, after a near death experience trying to figure out how the interface builder / outlets and classes work, the code is working, I just would like to make unglify it.
Thank you!
The problem of repeating code which you describe has an elegant solution. Objective-C supports something called a "category", which allows you to add methods to a class. A common use for this is to customize navigation and tab bars. In Xcode 4, you would do something like this to add a category on UINavigationBar:
Hit Command+N or open the "New File" dialog. Next, choose "Objective-C category" from the Cocoa Touch menu:
Click Next and you will be prompted to enter the name of the class that you would like to add methods to as a category. It should look something like this:
Then, you should end up with a save file dialog. A quick note about convention here. Convention is to name a category after the original class, the plus sign, and then a description of what you're adding. Here's what yours might look like:
Once you save your file, you will need get something like this:
Look at that beauty. You can now override the default drawing/init methods as well as extend the functionality of the navbar.
I'd suggest looking into the init and drawRect methods, although I don't remember which ones people use. Also, please note that while under NDA, this may change in iOS 5, so just be prepared for that possibility.
Why not define a UIViewController subclass which sets the title view via self.navigationItem.titleView and have your other view controllers extend from that class? Then you're sharing that behavior across all of your controllers without repeating the implementation.
I'm trying to learn Objective-C and iPhone programming, but I'm stuck with a problem. I have a utility application, and I have a text on my MainView and a button that change the text when I click it. Easy, and workes great. But what if I wan't to place the button on the "backside" in the FlipSideView, and still make it change the text on the frontside (MainView)? How do I get the views to talk together? I have tried a lot of different things, and searched for an answear, but can't seem to figure it out.
Would be great if someone had a answear, or maybe a link to a tutorial/example.
I suppose you've used the template which implements the following method in the MainViewController:
- (IBAction)showInfo:(id)sender {
FlipsideViewController *controller = [[FlipsideViewController alloc] initWithNibName:#"FlipsideView" bundle:nil];
controller.delegate = self;
...
}
As you can see it sets the delegate of the FlipSideController to the instance of the MainViewController.
A way would be to put an action into your FlipSideViewController, something like this:
- (IBAction)changeTextInMainView
{
[(MainViewController *)self.delegate changeText];
}
which is triggered when touching your button on the backside. You've got to wire it in IB as well as add the method to the header.
Then implement something like this in your MainViewController
- (void)changeText
{
self.myLabel.text = #"text changed to this";
}
Add this method to the header as well.
Another more elegant approach would be to save the text of your label in a property(maybe in it's own model class) which can be accessed from any view, by passing it by reference down the controllers. Then add a Key Value Observer from each viewController to the property which should show the text and update the view.
I am using the three20 launcher to get a homescreen feel in my app. I just implemented the basic launcher. I have two things that I want to accomplish.
First off, I would like the user to push a UIButton or whatever in a DIFFERENT view controller that the TTViewController and an item be added in the launcher, how would I do this?
Secondly I would like to know how you could do a view where the user could add all the information to add their own item in the launcher? This isn't as necessary as the first thing.
I would really like to know some of this and deepen my knowledge in the three20 launcher.
Just setup a way for your view controller to talk to the launcher, either by delegation, notifications or whatever you want, then add the item like this:
TTLauncherItem *item = [[TTLauncherItem alloc] initWithTitle:#"title"
image:#"http://imageURL"
URL:#"http://URL"
canDelete:YES];
[_launcherView addItem:item animated:YES];
[item release];
I'm a newbie programmer and I have played around with the SDK for a while. How do you create a homepage that has a button that will bring you to another view (the content of the app)??? If you know can you list the steps in order or link a tutorial site (It woul be awesome if the steps had code with it I needed). Thanks!
I would recommend getting a good book on iPhone programming. What you want to do is set up a UINavigationController, add the button to the first view, set the action of the button's touchUpInside to call the showContent method. Then implement the showContent method to push the Content view controller.
- (IBAction) showContent{
ContentViewController *myContentController = [[ContentViewController alloc] init];
myContentController.title = #"Content";
[self.navigationController pushViewController:myContentController animated:YES];
[myContentController release];
}
Have a read up on the documentation for pushViewController and UINavigationControllers, then follow this tutorial.