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

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.

Related

How to find the UI element connected to a specific IBOutlet?

Is there any way to find which UI element an IBOutlet declared in code is connected to?
Go to your view controller file where you have declared IBOutlet (.h or .m). Then you can see left side of each variable declaration there is a dark grey round image. (It is filled if you have connected that IBOutlet with Storyboard/Xib unless it is unfilled.)
By clicking that image you can see small popover which shows connection of outlet. See below image will show you.
You can search for the IBOutlet property name in the project directory.
There you will find the corresponding xib file and UI element.

No Action Connection Option

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.

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 access IBOutlets declared in superclass?

I'm currently refactoring a couple of view controllers that share a few IBOutlets and IBAction methods. I moved the outlet declarations and the IBAction method into a superclass, cutting these out of the subclasses.
Now, when I open up Interface Builder, I find that I can't see the outlets or actions declared in the superclass. The connections still exist, as I'd wired them up before the refactoring, but they're grayed out. (It's important to note that the connections also WORK, as my action fires on a button press, and my outlets are modified properly.)
The question is, how can I get interface builder to recognize outlets from a superclass? Is this possible, and, if not, what do you all recommend?
(Just for fun, here's my superclass header file:)
#interface TFMainViewController : UIViewController {
UIImageView *logoImage, *thinkfunImage;
UIButton *buyFullButton;
}
#property (nonatomic, retain) IBOutlet UIImageView *logoImage, *thinkfunImage;
#property (nonatomic, retain) IBOutlet UIButton *buyFullButton;
-(IBAction) buyFullVersion;
#end
EDIT: in case anyone's wondering, I'm using Xcode and IB 3.2.5, with the iOS 4.2 SDK.
I didn't realize it was even possible to connect to superclasses in interface builder until about an hour ago. Since this was the only question I could find regarding how to do this, I'll add my answer, even though this question is old. My answer is with regard to Xcode 4, not Xcode 3.
As far as I can tell, you can't connect to outlets in a superclass using the assistant editor, but you can do it by clicking on "File's Owner" in IB. That should show all the outlets in Utilities->Connections Inspector. You can then Ctrl+Click on the outlet in the inspector (click on the '+' sign), and drag it over to your view in IB.
The solution for the problem with the IBOutlet .. is to change the class type to the Base Class in the identity inspector
connect using Control + drag and drop and
change it back to the child class
This works for me
BTW: i used Xcode 6
IB should be able to see outlets from superclasses, I have done this a number of times with no issues. Are you sure you are importing the superclass correctly (using #import instead of #class)? IB needs some way to track back to the superclass.
Switching between the super and subclass in the identity inspector allows you to connect your outlets across the classes. The only issue I found is when you attempt to do this with a UITableViewCell and its subclass. I wanted to re-assign the default textLabel and detailTextLabel instances to labels I create in Interface Builder. The workaround is to create substitute labels and then override the getters to point to these instead.
I'm pretty sure that IB only looks at the actual class you're using to find outlets, and not at superclasses. I think that the easiest solution would be to leave the instance variable declarations in the superclass, but duplicate the #property lines in each subclass.
I'm doing this in XCode 3.2.6. I started with outlets connected to a class, and then made a subclass with additional outlets. When I changed the File's Owner class to the subclass, IB showed the superclass outlets as greyed out. I switched File's Owner to the superclass, then back to the subclass and now all outlets are showing not greyed out.
The simplest way: create interface and implementation files for your subclass(es)!
Perfect example: Juggleware's awesome ShadowButton Subclass of UIButton.
Make sure to create the .h & .m files in your project.
NOTE: There is no need to #import the header files at all since this is simply a class instance of UIButton.
In Interface Builder:
Select the element you which to connect.
Go to Utilities -> Identity Inspector
Change the Class to your subclass (or superclass). NOTE: You might have to type in your subclass name and hit ENTER.
You're done!
Even if you have declared a basic class (UIButton) as IBOutlet in your header file like so...
// YourViewController.h
#interface YourViewController : UIViewController {
IBOutlet UIButton *mybutton;
}
...the class you've set in Interface Builder (ShadowButton) will overwrite it since it's in the view layer.
The best part about this approach is that your code doesn't have any messy dependency issues.
On the project I am currently working, we have a BaseViewController with a UIScrollView as IBOutlet and handles keyboard appearance/disappearance events and slides the content accordingly. At first, I could not connect to that IBOutlet, than solved the problem like this, which is similar to Sosily's answer:
BaseViewController has an IBOutlet, called contentScrollView. I can see 5 previously connected outlets, which are UIScrollViews on other UIViewControllers, created by people who previously worked on the project
I tried to connect my UIScrollView as the contentScrollView. Although my UIViewController is a subclass of BaseViewController, I cannot connect it.
I tried to connect already connected UIScrollViews as the contentScrollView. Although all UIViewControllers are subclasses of BaseViewController, I cannot connect them again, as well. So, I started to look for a trick.
I have created the same contentScrollView IBOutlet on my own UIViewController, connected the scrollView to my own contentScrollView outlet and removed the one that I have just created.
Now the scrollView is connected as contentScrollView to File's Owner, but the only contentScrollView belongs to the BaseViewController. Tested and verified that keyboard events are handled correctly.
I ran into a similar problem with a superclass, but it was due to a bug in Xcode (8.2) where Interface Builder doesn't show outlets in the Connection Inspector if those outlets have been declared with a _Nullable type annotation for Swift compatibility.
Using nullable inside #property's parentheses appears to work around the problem.
This Xcode bug seems to affect outlets in any class (ie. not just superclasses).
I had the same problem, and it turns out it was because in the superclass I had the IBOutlets declared as "_Nullable".
Example:
#property (nonatomic, strong) IBOutlet UITableView *_Nullable mySuperTableView;
When I removed the _Nullable, suddenly the IBOutlets reappeared in IB and all was good again.
(I had only set them to _Nullable because Xcode was complaining "pointer is missing a nullability type specifier"... (don't know why). )

Resources