No Action Connection Option - ios

I'm following along with Big Nerd Ranch's iOS programming book. In chapter 11, it has us control drag from a camera button into the method area of a DetailViewController.h file. The instructions tell us to select action from the connection drop down menu, however, the only options that are available when I do this are outlet and Outlet Collection.
In the book, the result is supposed to look like
- (IBAction)takePicture:(id)sender;
However, in my case, I get this when I choose the outlet option
#property (weak, nonatomic) IBOutlet UIToolbar *takePhoto;
I'm concerned that if I just delete the code and replace it with what it says in the book, I'll still have the problem of not having established the proper connections via the control click and drag. Can you tell me what I might have done wrong when it failed to create an action?

The problem was that I didn't control drag from the camera button, but rather the toolbar in which it was contained. Hence the action button wasn't available.

Related

How to connect an IBOutlet and IBAction to a View Controller without using the Assistant editor

I know the second button here shows the Assistant editor:
And I know how to make an Outlet and Action by Control dragging from an object in the Interface Builder to the View Controller code. Ideally it should be as easy as the documentation makes it look:
But this is usually what Xcode actually looks like for me when I press the "Assistant" editor:
A mess. I have to minimize lots of things, try to get the storyboard object in view, and then go find the right View Controller. All this before I can do the Control-drag.
Is there a way to make the connection without using the Assistant editor? (And preferably without having to type a lot of code in myself.)
Don't press the assistant editor button. Sometimes it opens a random file instead of the one you want.
When you are in Storyboard, Option click on the .h file that you want to open in the Project Navigator. This will open the proper .h file to add the outlets or actions.
When you're done, close the Assistant editor right pane (which is displaying the .h file) and you will be back in Storyboard.
Yes, you can do it without the Assistant editor and without writing lots of code. It requires learning to do two things:
Use code snippets
Use the Connections inspector
Create code snippets for the IBOutlet and IBAction
Normally when you create an IBOutlet and IBAction with the Assistant editor it automatically adds code like this to your View Controller:
#IBOutlet weak var myOutletName: UIButton!
#IBAction func myActionName(sender: AnyObject) {
}
You could type this all yourself and then add the connection in the Connection inspector, but why do all that typing? Just make a code snippet that will autocomplete. Drag the code to the Code Snippets library in the Utility panel.
Give it a title and most importantly, a Completion Shortcut. I called mine "ibaction" for the #IBAction code.
Now all I have to do is start typing "ibaction" and I can autocomplete the code snippet. I only have to edit the name of the action. It is a similar process for the Outlet.
Read more about creating code snippets:
Xcode Snippets
Creating a Custom Code Snippet
Now all you have to do is connect the IB object to the code.
Make the connection with the Connections inspector
First, click the object in the storyboard that you want to connect. For me, I am using a Button.
Then select the Connections inspector. It is on the far right.
Alternatively, you can right click or control click the object to get a menu.
Then click the New Referencing Outlet to connect it to your Outlet or the Touch Up Inside under Sent Events to connect it to your Action.
For whatever reason I find that sometimes I need to drag just a little bit after clicking the "+" button to get the menu of available connections to show up.

Not sure how to setup view object and connect with IBOutlet code

I am trying trying to copy all of the functionality of this example app provided by Apple called AVCam: https://developer.apple.com/library/ios/samplecode/AVCam/Introduction/Intro.html#//apple_ref/doc/uid/DTS40010112-Intro-DontLinkElementID_2
I am 99% done with copying this code, but I just have one final problem. I have an IBOutlet statement that looks like this: #property (nonatomic, weak) IBOutlet MediaCapturePreviewView *previewView;
According to the Apple sample code, this outlet is supposed to be connected to a View object that has been placed on top of the normal/default view.
Here is a screenshot of what the Connections Inspector looks like in the Apple example:
You will notice that the IBOutlet called "previewView" has been connected to something called the "Cam Preview View".
Also, in this screenshot, you can see that I am able to select this View object by itself and that it shows a Referencing Outlet in it's connections inspector for the same IBOutlet and View Object:
My problem is that I cannot get the IBOutlet code to connect to this View Object. I have tried the normal behavior of clicking and dragging to make the connections but it just wants to create a new outlet. It will not let me connect to the outlet that I have already created.
I have been playing with this for 2 hours now and just can't get it to work like Apple's sample code.
Any help is greatly appreciated thank you.
In your .xib file, make sure that UIView class is assigned as AVCamPreviewView instead of UIView.
A few possible solutions:
Save the file with the IBOutlet you're trying to connect up (the source code, not the IB)
Clean, rebuild
Restart Xcode.

How to establish outlet connection in Xcode

I am following a tutorial HERE on creating a table-view controller in Xcode. I am using the latest version of Xcode (Xcode 5). At the top of the tutorial it says its for iOS 5.
In the tutorial a cell is created and an UIImage and a few labels are dragged onto the cell. It goes on to say to Ctrl-Click the white space of the cell and then drag to the labels and image to establish the outlet connection. See screen grab from tutorial.
When I do this, I dont get the same options as per the tutorial. The only options I get are shown below in this screen grab (note I chose to only add one label and leave out image for the purpose of my application).
Can anyone please let me know what Im doing wrong or how else I can create this connection? I have Googled it for the last hour and all I could see was how to create IBOutlets.
Alternatively, does anyone know of any tutorials similar to this one? This one suits my needs perfect as I will be creating a view similar to the second part of this tutorial. Like I mentioned Im working with Xcode 5.
Although this might be a little late, I recently just stumbled upon this problem myself and figure out the answer. I used the same tutorial as you, and could not seem to generate the proper options when I did the control + drag.
Instead of dragging the labels to the whitespace of the custom cell, you will be dragging from the Connections tab of the custom cell. To do this:
First, make sure your labels are properly declared in CarTableViewCell.h and synthesize them in CarTableViewCell.m.
Second, change the custom class in the storyboard for the prototype cell from UITableViewCell to CarTableViewCell.
Next, click on the cell prototype in storyboard. Using Utilities, go to the connections tab (the last one with the arrow). If everything is linked properly in your header files, you should see "makeLabel", "modelLabel", and "carImage" under the Outlets section.
Finally, click the little circle next makeLabel and drag it over to the proper label in your custom cell. Do this for modelLabel as well as carImage, just using the associated outlet and label or imageView for each.
This solved my connection problem, and after following the rest of the tutorial, everything worked!
Is your cell a custom cell. If not click on your cell and go to the attribute inspector then under table view cell choose the style as custom
Is your TableViewCell connected to the "CarTableViewCell"?
Click on the cell and make sure the custom class is set to CarTableViewCell.
And your .h file matches the one in the tutorial
#import <UIKit/UIKit.h>
#interface CarTableViewCell : UITableViewCell
#property (nonatomic, strong) IBOutlet UIImageView *carImage;
#property (nonatomic, strong) IBOutlet UILabel *makeLabel;
#property (nonatomic, strong) IBOutlet UILabel *modelLabel;
#end
Try again, and it should be like the tutorial.
-Cong

How to get UIWebView working

(Link to errors here: http://imgur.com/a/AF87N)
I'm starting to work on iOS development, and I'm relatively new.
I was looking for tutorials on how to display web content in the app, and so I used the UIWebView.
In the tutorial I found I followed the steps exactly, but when I went to do the last step (linking the outlet) I got an error.
The two files I edited are DataViewController.h and DataViewController.m
This is the tutorial I followed: http://www.youtube.com/watch?v=NFffF9tRbak
I'm using XCode 4.6
Am I doing something wrong?
Renaming may still cause some erors, there is a chance, so its better to set the connections again.its quite simple.
You can solve this by following these steps:
1.
Click on the cross sign left to Web View , that will remove the invalid outlet.
2.then, connect the existing #property(nonatomic, retain) IBOutlet UIWebView *myWebView by control dragging the '+' sign left to the property outlet to your webview in the Interface Builder.
This will solve your problem, happens just because you are new to xcode. Will get better as soon as you get familiar.
EDIT:If its still not clear, see the screen shots below;
your outlet in yourviewcontroller.h may be like this now,
and in your xib,
it may look like this.
So what you should do is, just control drag the while blank circle left to #property outlet (first image) to the webview in your xib (highlightened one in second image). It will connect itself.
hope its clear now
Regards
Change your outlet name from webView to myWebView in outlets
Edit:
or change your UIWebView object name from myWebView to webView in your code

how to connect an IBOutlet to textview control in iOS?

I'm really a newbie on iOS and I don't know how to connect the UITextView object to the textview control on *.xib file? Is there any way to set the unique ID to a control on iOS?
Currently, I have declare an IBTextView as below:
HelloViewControler.h file:
#interface HelloViewController : UIViewController{
IBOutlet UITextView *txtTextMe;
}
#property (retain,atomic) UITextView *txtTextMe;
- (IBAction)buttonPressed:(id)sender;
#end
HelloViewControler.m:
#synthesize txtTextMe;
- (IBAction)buttonPressed:(id)sender{
txtTextMe.text = #"Button clicked";
}
Code to update a string to textview control:
txtTextMe.text = #"Button clicked";
No Error. But when I run the code, the string "Button Clicked" wasn't updated to the textview.
Hold CTRL and click and drag from the item in the .xib into the code. This will create either an IBOutlet or IBAction (you chose via popup) and link it to the object on the .xib.
It can also be done via the left hand inspector if you have already created the code.
If you are new to iOS programming and Xcode I would very strongly recommend you look at Apple's tutorials on the developer portal. They have some excellent introductory guides with step by step instructions. The second one covers using storyboards and is a really great introduction to storyboards, Xcode and the iOS SDK - link below.
Your Second iOS App: Storyboards
Right-click on the textview control in the NIB file. A HUD-style menu should appear.
Under "Referencing Outlets", drag from the circle to the right of "New Referencing Outlet" to "File's Owner" in the "Placeholders" section to the left. When you release the mouse button, another popup menu should appear.
Pick txtTextMe from the menu.
Build and enjoy :-)
This is my fault. I drag a UITextField to *.xib file but I declare an IBTextView in my code. Thanks all.

Resources