MonoTouch and MVC - hook 2 Views to same Controller - iphone

I need to write an app that runs for iPhone and iPad.
The issue I'm running into is how do you setup an iPadView and an iPhoneView to hook to the same controller?
In other words, I don't want to have any duplicate controller code--I should only have to make a different view for each device.
Right now I link up view->controller by choosing "Add->New File->iPhone View with Controller", and this works for one device. But the code in the event handlers I have wired up should not have to be duplicated by going to "Add->New File->iPad View with Controller".
A link to a tutorial may help, I have been doing .Net Windows development for a while but still learning iPhone and MonoTouch.

This link talks about code generation for .xib files:
MonoTouch Doc
Apparently you can just delete your .xib.designer.cs file to turn off the code generation. Is this the right way to do it?
Otherwise I'll mark this as the answer.

Can you not just have a base controller and then inherit from that in both view controllers?

Related

Xcode 4.2 is missing a .xib file?

So I'm pretty new to programming, so I downloaded Xcode 4.2 and got to work. I watched many online tutorials and the main problem I was having was that all the tutorials were for Xcode 4 and not 4.2, meaning when you chose empty application setting, it was missing the .xib file. So I found a tutorial on how to create a .xib file. I got through it all except for one step, and that was to drag the from the window outlet of the xAppdelegate to the window. I've tried this over and over, but it doesn't work.
Here is the tutorial if anyone needs to see it http://www.trappers.tk/site/2011/06/16/mainwindow-xib/
Please someone help me!
You need to hold Ctrl while dragging, else it will not work.
Guide.
As you Control-drag from an object to your source code, Interface Builder indicates where a new binding is valid. After you’ve made the connection, Xcode displays a dialog you use to configure the binding. You can use the dialog to configure all aspects of the binding.
Interface Builder uses the Xcode index to determine which key paths are valid, and can also discover what controller it should connect through—you can therefore connect from a user interface element such as a table column to a property in a model class header.
Check out the video here.
You should choose a SingleViewBased Application instead of Empty Application then study all files that how they connect with each other. You can choose Master Application also. They will help you.
see this Hello world Tutorial click me.
And Youtube is the best way to learning for beginners. Search tutorial video because action teach more than the text.

Cannot find window-based application on XCode

I am using XCode 4.2 and for some reason I cannot find the template for window-based application. Is there an extra step that I need to take here?
There is no longer a Window-based Application template starting from Xcode 4.2.
You have two other choices of "bare-bones" templates:
View-based Application template, which gives you a view on a storyboard to start with. It is similar to the one found in previous versions, except the view now resides on a storyboard which Xcode 4.2 makes use of.
Empty Application template, but you'll have to manually create and wire up a window nib file if you want to design your application in Interface Builder. It's nothing more than a trivial extra step, though.
If you can't make use of storyboards (e.g. to deploy to iOS 4 and earlier), you most likely need to go with the empty template. For the main window, just make a new Interface Builder file and assign it as your project target's Main Window.
Here are two very useful links:
The first one is a discussion on the Big Nerd Ranch forum where they discuss this issue - that the XCode 4.2 has done away with the Windows-template. They have a Template that you can use to add the "Windows-template" to your XCode installation. I have NOT tried this approach but you can try.
http://forums.bignerdranch.com/viewtopic.php?f=73&t=3336
As you dig through this thread - you will come on another site. This a blog post by Jeroen Trappers - on how to "manually" add the missing elements to an "Empty-application" template to make it "Window-template". I have followed these steps and they worked very well for me. In the process of going through these steps it does help you understand what is going on behind the scenes.Here is the URL to the post:
http://www.trappers.tk/site/2011/06/16/mainwindow-xib/
Window-based Application is now Empty Application. Just gives you an app delegate and a window. You build the rest.

Displaying XIB on UIView!How can i set it?

How can i display a XIB interface on an UIView!Please be simple!
a UIView interface built in a XIB can be displayed by linking that XIB with a UIViewController.
Check out the Apple documentation About Windows and Views.
And you can see how a XIB is set up just by creating a new project in XCode and choosing "Single View Application" as a template. If you're using XCode 4.2, the "MainStoryboard.storyboard" file appears to be the new name for a XIB file.
Which reminds me I should go check out the WWDC session online that talks about this -- and you should too. If you're a registered developer, it's free to check out! My educated guess is that the "Designing User Interfaces for iOS and Mac OS X Apps" session (at https://developer.apple.com/videos/wwdc/2011/?id=110) is the one you want to see.

Adding iPad XIB to a View Based Application Template Application in XCode 4

I've created a View Based Application in XCode4; when creating the application I selected iPhone as the Device Family:
The application was created with the following files:
I designed the UI on the TestushViewController.xib file and without adding any code in the Delegate files, the application is uploading immediately to the TestushViewController.xib view and I'm very happy about it.
Now I want to add an iPad xib. How do I do that?
(I knew how to do it in XCode 3, but I used some code in the Delegate file, and now if I try to use the same code it doesn't work because the template default implementation works differently - Apple uses #class TestushViewController and self.window.rootViewController = self.viewController and it goes directly to the iPhone.xib. I don't know how to go around it without changing the entire thing to the way it was done in XCode3)
You'll need to structure your code in a similar way that the Window Template does. The file structure that template uses when the "Universal" option is ticked at creation is:
App Name/
AppNameAppDelegate
iPhone/
AppNameAppDelegate_iPhone
MainWindow_iPhone.xib
iPad/
AppNameAppDelegate_iPad
MainWindow_iPad.xib
The iPhone and iPad AppDelegates are simply subclasses of the AppNameAppDelegate
#interface YourAppNameAppDelegate_iPhone : YourAppNameAppDelegate {}
In your target summary you can set what .xib file is initially loaded for each device. It is called the "Main Interface" and has a pulldown menu.
Quite frankly, if you're wanting to do a universal app (iPhone + iPad) it's probably easier just to start with the Window Template and add in your view controllers instead of starting with the View template and trying to change it up.

IPhone App Build Successful But nothing shows

Very new to Iphone development here, I have a project which is successfully building (which is a first for me :) It loads the simulator but it just closes as soon as it loads, how can I debug this? It appears the Interface Builder xib files are not loading, I've added a xib thats from a hello world project, (they have different project names) Is this an issue?
Any advice would help,
Thanks!
You probably have an error in the Debugger Console. If it has to do with the XIB, it could be that you simply got the name wrong.
Another simple mistake is trying to use Outlets before viewDidLoad is called (for instance, in init).
In either case -- the message in the console will help.