new xib in xcode4 - iphone

I develped an iPhone app. Now i would like to do it in iPad. To do this I have to create the new .XIB files and linked to his Class.
I don't know how to create a new .xib in xcode4. Could somebody help me?
Now, to solve this problem, I create a new file with his .XIB, delete the .m & .h and link the .XIB with my class.
Thanyou.

In order to create a XIB file in XCode 4, just go to the main menu, File->New->New File..., and from there choose User Interface from the iOS section. Then choose View (if that's what you want), device family and finally save.
Hope it helps.

We also need two more nib files, one for each of the two content views we just created. To create these, single-click the Resources folder in the Groups & Files pane so that we create them in the correct place, and then press ␣N or select New File... from the File menu again. This time, when the assistant window comes up, select User Interfaces under the iPhone OS
heading in the left pane .
Select the icon for the View XIB template, which will create a nib with a content view, and then click the Next button. When prompted for a filename, type BlueView.xib. Repeat the steps to create a second nib file called YellowView.xib. Once you’ve done that, you have all the files you need. It’s time to start hooking everything together.

Related

Navigate in Xcode between UI to is related controller and from controller to UI

In the Android Studio, every view have a separate file and user can go from Java file to its view file by click on this
setViewContant(R.layout.my_view);
Is there is any way in Xcode that can take user form viewController.swift to is related layout file. Because it's totally Spaghetti in Main.Storyboard
Unfortunately I don't remember a better way than just search the ViewController class name.
Right-click on the ViewController class name
Select "Find Selected Text in Workspace"
In the left panel will appear the list of files which have occurrences of the searched word
Select the entry in your storyboard
btw: I would suggest to split the Main.storyboard in smaller ones! ;)

My recent changes in NIB file is not displayed in ios simulator-closed

I've applied changes in interface builder for my app which has labels in it. I just changed the name and position of a label and in addition to that I changed the font of a text view in my app. When I started to run my app, the font remains the same as previous one and none of the labels are displayed in it.
Can anyone help it pls?
in Xcode try this: main menu:product:Clean
if not enough: main menu:Xcode:preferences: -> click over locations icon:
click over the little gray right arrow for derived data:
that will show you the finder folder "DerivedData": delete it.
one other thing to try: in simulator, delete your app.
quite your xcode and then again open your project . Clear your build then run your code.
You should also make sure, that the interfacebuilder file is linked to the target you are starting in simulator.
To do this, select your xib and open the File inspector. There you should see a dropdown named "Target Membership" where you can link the xib to the targets you want.
Also be sure to have the labels defined as IBOutlets in your header file and link them correctly in your xib. Easiest way to do this is using the Assistant Editor and drag the outlet to the header file.
I had the same problem - but only on the iPhone non-retina in the simulator. Cleaning the code did not help. Restarting and rebooting did not help. But removing the app from the simulator worked. Now changes to my UI show up next time I run.
To remove the app from the simulator I did it just like on a real phone. I select the app icon with the mouse and hold it down the mouse button for a few seconds. Then the icon displays a small delete icon that you can select (the app icons shakes too).

What's the best way to copy xib file(s)?

I have a ViewController.xib that I would like to duplicate so I can make some settle changes to the duplicate copies. Everything is laid out how I like it in interfaceBuilder and coded correctly in the original ViewController(.M & h.). Can this be done and what is the best way to do this?
Sadly, there isn't a way to directly duplicate a file from within Xcode. I've submitted a bug to Apple on this and you should too. It's not too difficult to do manually, though:
In Xcode, right-click on the xib and choose "Show in Finder"
Once Finder comes up with the file selected, right-click on the file and choose "Duplicate"
Rename the file as you need
Drag these new files back into your Xcode project.
Using FINDER, duplicate all three files and rename them.
Drag them back into the project in Xcode.
Rename the Class in the .h & .m files & start making your subtle changes.
However, if your changes are all just to do with positioning you could just use the one file and change the frames of the things you're moving about
OR
Just duplicate the XIB file, rename it appropriately, add to the project & make the subtle changes. Then you can load the ViewController with whichever XIB suits your needs...

Xcode 4 .xib Create iPad Version

I have an iPhone xib I want to turn into an iPad xib. In Xcode 3 there was a "Create iPad Version" menu option. How do I do this in Xcode 4?
I currently resized my xib, but when I turn on the simulated items (Navigation Bar, etc.) it shrinks the view back down to iPhone size.
This worked for me:
Make a copy of the .xib in the Finder.
Open the copied file in a text editor.
Change "com.apple.InterfaceBuilder3.CocoaTouch.XIB" to "com.apple.InterfaceBuilder3.CocoaTouch.iPad.XIB".
Change all instances of "IBCocoaTouchFramework" to "IBIPadFramework".
Search for sizes like {480, 320} and edit them. Or just reopen the file in Xcode and use the GUI to resize items as needed.
This also works in reverse, if you need to change an iPad xib into an iPhone xib.
in Xcode 4 it's quite hidden, but the option to convert XIBS in the app still exists.
Select the target (in XCODE4 it's shown when you select the project). Once selected use the contextual menu to "Duplicate" it. It will ask if you want to "Duplicate and transition to iPad". Then all the XIBS will be duplicated with the new iPad size.
On assessing my options, these were my thoughts:
Too much of a hassle to install xcode 3 and downgrade project
Don't want to mess with .xib file format - afraid it might break something that will show itself much later
Copying the same nib is imperfect (see the explanations in this thread)
So finally, what I ended up doing that works fine is:
Create a new file, choose "UIViewController derived" class
Check the "intended for iPad" checkbox
Name the file -iPad
Delete the .h and .m corresponding to the uiviewcontroller
Now populate the new nib with the same objects, structure and connections as the original nib
Check if on iPad, if so then load the new nib else load the old nib
The feature has been removed from Xcode 4.
Right now the easiest way is to use Xcode 3 for the conversion, since the nib (.xib) file format did not change.
Xcode 3 & 4 can now be both installed on the same system by simply selecting a different folder (see installation instructions on the disk image).
Another simple way in XCode4 is: Just copy the iPhone XIB in Finder; drag the copy in your project. Open the copied XIB in XCodes build in interface builder. Change the size of the top view in your NIBs hirarchy to iPads dimensions (e.g. 1024x748 for landscape with statusbar) - everything else resizes according to the autoresizing masks.
Works perfect for me.
If you make a new nib, it will ask you if it should be sized for iPad. That might be the easiest unless you've already done a bunch of work on it.
You will have to use the older version of Interface Builder to use the "Create iPad version using autoresizing masks". There currently is no option in Xcode 4 that will do this.
Using XCode 4, all you have to do is select the (iPhone-specific) .xib file in the project navigator, then select File... --> Duplicate...
Name the new .xib file the same as your iphone-specific one, but append ~ipad to the name. All your previous connections in the view hierarchy should be unchanged in your brand-new iPad-specific .xib file.
You can use this tool I made, based on the answer from "arlomedia":
http://iphone.dizzystudios.net/ConvertToiPad
just give it the iPhone xib path

How to copy a XIB to another project?

Simple. I have two projects in Xcode. In one of them I made a .xib file and I want to copy it to another project, so as to save some time redoing it.
I can't drag it to the other project, nor do copy/paste by command, nor copy/paste by the Edit menu.
Any suggestions?
Go into finder, find the .xib file and copy it to the directory of the second project. Then uses add existing files to add it to the second project.
Just drag and drop from one project window to the other.
Make sure that you check the "Copy items to the destination folder"
If you have more than one targets make sure that you check the appropriate target when you add it.
You probably have to reconnect all of your outlets, and if it crashes for some reason it means that there are connected outlets/actions which are not available in your code.
Here is how I managed to do this with XCode 10.2.1
Close the XCode project with the xib file you want to copy.
Drag the xib file from finder over to the new project. Make sure you tick the copy items if needed box.
If the xib file uses images for outlets, also drag the images to the new project.
There is no need to reconnect the outlets.