I have a project that has the header and the implementaiton files and loads a plain old UITableViewController from the .m but I have no way of configuring the View (I would like to do stuff like ad buttons and text fields onto the view instead of just having a table), should I create a .xib file so that I can modify the view? (Reason I don't just start a new project is that the current project has a bunch of other stuff like OAUTH processes that kick off at the AppDelegate stage to log a user into a system - and I need this functionality). So my question how can I create a .xib from the existing .m .h files and then add other objects which I can then code for.
An answer from this similar question:
"Here's a more step-by-step way to associate your new UIViewController and .xib.
Select File's Owner under Placeholders on the left pane of IB. In the Property Inspector(right pane of IB), select the third tab and edit "Class" under "Custom Class" to be the name of your new UIViewController subclass.
Then ctrl-click or right-click on File's Owner in the left pane and draw a line to your top level View in the Objects portion of the left pane. Select the 'view' outlet and you're done.
You should now be able to set up other outlets and actions. You're ready to instantiate your view controller in code and use initWithNibName and your nib name to load it."
If it's a UITableViewController, simply create a new XIB file via Xcode (File -> New -> iOS -> UserInterface -> View) and then add set the file's owner to your subclassed UITableViewController.
You'll likely want to re-do how the user interface looks -- in terms of dropping objects like the table view and buttons or whatever else -- into the XIB's view. It'll certainly save a lot of time versus trying to debug programmatically creating and adding subviews and actions.
And once that's in place, you can then make IBOutlets and IBActions to your heart's content.
Related
I am a bit new to iOS development. Am I going crazy here?
I am using xCode to create a paged application. I select new project with the language as swift.
When I go to add a new view to the application it adds a view with Objective C?? Why? I want to use Swift. Am I doing something wrong?
Adding more screenshots, how do I get the second view to show me the Swift code instead of the "UIKit" code?
Working Side...
Not working
3:
It looks like your Assistant Editor is automatically opening the underlying Objective-C header files rather than the Swift files associated with your View Controllers. Try clicking on Automatic at the top of the Assistant editor, then hovering for a moment to see if your Swift file comes up (it should appear above or below the UIViewController.h file).
If you haven't created a subclass for the View Controller you've created in the storyboard, you'll need to do that first, then assign that class to the View Controller in the storyboard. To do this, select File > New > Fileā¦, select Cocoa Touch Class, and make it a subclass of UIViewController (don't create a XIB file). Then, in your storyboard, click on your newly-created View Controller (you can select it from within the view hierarchy on the left), open the Identity inspector, and set its Class to the subclass of UIViewController you just created.
If, for some reason, you've created a View Controller class and correctly associated it with the storyboard object and it's still not appearing, you can use the Manual selection in the Assistant editor to drill down to the file you want to appear.
I can't find the way to add my custom data source class of UICollectionView in the storyboard. The data source class has an interface like this:
#interface CalendarDataSource : NSObject<UICollectionViewDataSource>
I try to find the calendar data source in the scene sidebar but I can't. So I can't seem to link the class to my UICollectionView. Is there something I should do but I didn't?
If you want to reproduce the similar problem, just create a new project in XCode5, set up a UICollectionViewController, and create a new class just like above.
I'm currently rewriting the project described in http://www.objc.io/issue-3/ The Github repo is https://github.com/objcio/issue-3-collection-view-layouts This project managed to do this, however. My code is almost the same to the project but can't run because viewcontroller.collectionView.dataSource is uninitialized.
Doing the initialisation programmatically is another issue, but please tell me in the comment because all I got from the internet is setting dataSource to self. But setting it to self doesn't require introducing a new retained data source object, which I got stuck on.
Go to the Interface Builder.
Right-click on your Collection View in the storyboard, delete dataSource outlet (if any).
Type "Object" in the search text field of the Objects Library and drag an 'Object' to your view controller containing UICollectionView (i.e. do the same as you add any view or view controller to storyboard scene, with the exception you add not a view or view controller but an abstract object).
In the left-side 'Scenes' panel of your storyboard, highlight just added Object; in right-side panel go to the 'Identity Inspector' and type CalendarDataSource instead of pre-defined NSObject. In left side panel ('Scenes'), 'Object' will be renamed to 'Calendar Data Source' automatically.
In the left-side 'Scenes' panel of your storyboard, control-drag from your UICollectionView to the 'Calendar Data Source'; in pop-up appeared, select dataSource outlet.
You've done!
I am working on one view controller which has three static screens which i m going to show to user for first time when he installs the app, for next time forever i will show him main functional view.
Problem is
When i have created viewController class i never selected xib option.
Now i have added two xib's (iPhone and iPad) in project.First i deleted the present view from it then I have created three static views in each which contains some label and one button in each..
I want to add those views in my view controller's view. and i want to add targets for buttons in those view.
I am unable to reference outlets in my class for all three views
and can't add target for buttons in my viewController.
How can i do that??
Please help......
Solved it..:)
Problem was when i have added new xib file to project.i deleted the present view controller view from xib...thats why xib was unable to find any of the projects view controllers in custom class drop down
When you click on the File's owner on the left while the XIB is opened:
Select the the third icon on the far right, and make sure the correct class is selected under Custom class, the green textfield:
You need to select File Owner then go to the identity inspector in right pan of Xcode where you can select yor Xib name :)
I have a XIB file inside of which there are some connections between some objects and the file's owner (a ViewController). I'm getting anything shown in the utilities sidebar that you can pop out from the sidebar in order to do some configuration stuff. It shows as "Not Applicable". I had created the XIB file along with the ViewController file (check marked the option in the New File sheet) so the file's owner was preconfigured to the ViewController by default. I have already made the connections and added the necessary IBAction selector for the UIControl stuff. Its just that whenever i select an object in the view frame, its config doesn't show up in the utilities. I have another XIB file hooked with some other view controller, and don't have the problem. What's up with Utilities sidebar????
I find restarting xCode often fixes this annoying bug.
I added a custom view controller class with interface (.h), implementation (.m) files, and UI (.xib) to an existing project.
When I ctrl-click and drag between the nib and the interface, it will not place an outlet or IBAction when I drag, so I can't link a UI element to a property. Also, XCode does not bring up the corresponding interface file when I view the nib in assistant editor mode.
Note: I changed the name of the custom class. I changed the filename and the references to it in the source.
Make sure you click on file's owner on the left and then in the identity inspector on the right, put in the custom class. You should then be able to make connections.