Can't ctrl+drag into ViewController.h from second Viewcontroller - xcode

I am building an iOS app for fun and here is where I run into trouble. I can insert an outlet and action in the ViewController.h files directly from my first View Controller through the ctrl+drag method; however, when I try ctrl+drag on the second ViewController it will not allow me.
Ctrl+drag on first ViewController
Ctrl+drag on second ViewController

You have the wrong document open in the assistant editor. It should be ViewController.h, but you are displaying UIViewController.h.
Check you have correctly set your second view controller to your custom class ViewController using the Identity Inspector (third of the right hand utility panels) then make sure it's header file is the document you are displaying on the right.
update
From your comments, you are having difficulty setting the second view controller to a custom class.
Here is how you select it in the storyboard. Note that you are selecting the View Controller, not it's topmost View

Copy and paste the class in the field "Class." You then need to press ENTER to take effect. Example

Related

xCode can't Control-drag into .m file

I'm trying to change the results field in the sample app SimpleURLConnections in the AppleDeveloper Library from an Image View Object in the GetController.m to a Text View so that it will display responses that aren't images. (I know some code that checks the response type also needs to change.)
When I drag a Text View object (or ANY object) from the Utilities pane to the MainWindow.xib in the editor pane, it appears to be created ok but when I try to Control drag from the Text View into the #property area of GetController.m, I don't get any "Insert Outlet.." popup or new entry in the GetController.m file? (By experimentation, I can get it to populate an IBOutlet in the AppDelegate.m file.
What am I doing wrong?
Thanks,
Rick
It may be because you are doing it wrong.You added the textview to mainWindow and Getcontroller is a controller entity[its a view controller i think.] .An xib will be connected to the outlet if and only if it has the custom class correctly set to that class.
Add a view controller with custom class in attribute inspector set to that Getcontroller and then you can connect the outlet
When u drag the control to the **.m , u should press the key "control",

Standard Back Button in XCode (XIB)

I can't get the standard back button of iOS into a navigationBar because I can't find it in the Object Library, so can I do it with code or something else?
I just want the normal, standard, blue back button - you know which I mean.
To "automatically" have a back button you need first have a UINavigationController. Then you need to take a different UIViewController and add it as the root view controller in UINavigationController's init method:
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:someOtherViewController];
Be sure to also set a title for someOtherViewController, usually in it's viewDidLoad or initializer. I'll tell you why this is important in a second:
self.title = #"Some other VC";
Then take a second UIViewController and push it onto your navigation controller:
[navigationController pushViewController:anotherViewController animated:YES];
You now have two UIViewControllers on your navigation stack: someOtherViewController and anotherViewController.
Your view will now have a back button with "Some other VC" in it. This is the title of the view controller that was just moved out of view:
http://developer.apple.com/library/ios/#documentation/uikit/reference/UINavigationController_Class/Reference/Reference.html
http://simplecode.me/2011/09/04/an-introduction-to-uinavigationcontroller/
I would also suggest reading up on how UINavigationControllers work and searching this site a bit more for customizing the back button. There are plenty of threads about it.
You can't add the back button yourself. The back button is part of the Navigation controller. If you embed a Navigation controller into your view(s), the back button will appear and be populated by the name of the previous view.
If you're using storyboards select your view controller, then in top menu choose "editor" -> "embed in" -> "navigation controller".
Edit: Here is an exmaple.
I'm running Xcode 7.2. This was driving me crazy, but I figured it out. Here are all the pieces you need to make the Back button appear (make a test project to prove it):
1) You have to have a Navigation Controller and it has to be set to be the initial view controller. So add the Navigation Controller, you will import two tables. Click on the Navigation Controller and on the properties list, check the box that reads "Is Initial View Controller". You will now see and arrow pointing to this view.
2) In our case we want a ViewController and not the included / connected TableViewController, so delete the TableViewController (RootController) and add a new ViewController.
3) Connect the Navigation Controller to the new ViewController by clicking on the top bar of the Navigation controller and orange circle with the arrow pointing left. Hold the Control button on your keyboard down and click and drag from the orange circle to the ViewController and let go. When given the list of options on how to connect the two views, select 'root view controller'.
Done! Now you the functioning navigation bar and you automatically get the back arrow on all segues added. Test this. Add another ViewController and connect to it with a button on the existing ViewController. Use the Control-click-drag approach from the button to the newest ViewController. Select the 'show' option for the new segue you created.
Run it. You'll see the back option has automatically appeared when you click the button and moved to the newest ViewController.
This is all provided by the Navigation Controller, but only when you make another controller the RootController. Happy navigating!

Is there a way to set referencing outlet in Interface Builder without Ctrl-Drag

So I'm just trying to create a very simple app for demo purposes here:
Created a Single View Application, using storyboards
Added a UIView to the storyboard
Added the following code to my controller's header file:
#property (weak, nonatomic) IBOutlet UIView *myView;
Now, I understand that I can link the UIView to the controller by:
arranging my code such that the header file is next to the storyboard
holding down Ctrl key and dragging it to the property in the header file
My question is this: can I do this without Ctrl-drag? And if so, how?
More specifically - it's annoying to have to put both my header file and storyboard on screen at the same time, and it seems there should be a way to make this connection without doing so.
I also understand that I can manually place the view by creating it inside my controller's viewDidLoad function, but I'd really like to use the interface builder to simplify / visualize things.
Edit: Is the answer to my question affected whether I use storyboards or xib/nib files? (I'd switch to use the one where it works)
you should be able to right click the element, and drag the "referencing outlet" item to the view's "File's Owner" in interface builder. There, it will give you a list of all available IBOutlets (matching the object's type).
In addition to Dima's answer, you can just as well use the Connection inspector in the Utilities pane

NSTableView not refreshing

I have a table view that gets refreshed two different ways. Both are through a button, and as a matter of fact, both are through the same IBAction in the same class!
Here's my problem:
The buttons are in two different .xib files, the button in the same xib as the table view works perfectly, while the one in the different xib does the method to get the new data, but it DOES NOT refresh the table. Same exact method, different results. To get the IBAction for the other button I simply dragged out an NSObject in IB and set its class to the class of my table view, which contains the IBAction, then hooked it up to my button.
How can I fix this?
Sounds like you're creating a second, parallel, object of your class in the second XIB. The button sends a message to that instance, which does some of the stuff you expect because it's an object of the right class, but it isn't actually the right object and isn't connected to your view.
What you need to do is ensure that both buttons talk to the same instance. This is easiest if the target is in the responder chain -- you should be able to set the button's target to First Responder and the message will find its way to the right place. Otherwise, you need to get a pointer to the target into the XIB, eg as an IBOutlet in the object that will be File's Owner.

IPhone XCode programming: view called from a navigation view doesn't set its IBOutlet attributes

I created a view Called ProgrammaView that appears when a row of a table is clicked.
This view has a UILabel, a UIImageView and a UITextView.
Now.
ProgrammaView's Outlets have to be changed by the parameter passed to a method of the view called iniz.
in this
image there is first the ProgrammaView.h and then the method iniz.
The problem is that the label and other stuff doesn't change!
I checked 3 million times that everything between the xib file and the controller is linked.
The trick to call iniz in the other viewcontrollers works well in other part of the program so i think is not that the problem.
Thank you in advance!
You need to call setNeedsDisplay to indicate that the view should be redrawn.
My understanding is that you start up and show view after that you update the values and expect the view to display new values.
You need to call setNeedsDisplay to indicate that the view should be redrawn. Try to add it at the end of your iniz method.
See apple doc.

Resources