Referencing outlet not showing up in xcode 6 - ios

I am trying to write my first hello world in xcode. I have two labels and two buttons in my view, and my AppDelegate.h file is like this:
#interface QuizAppDelegate : NSObject <UIApplicationDelegate>
{
int currentQuestionIndex;
// The model objects
NSMutableArray *questions;
NSMutableArray *answers;
// The view objects
IBOutlet UILabel *questionField;
IBOutlet UILabel *answerField;
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
- (IBAction)showQuestion:(id)sender;
- (IBAction)showAnswer:(id)sender;
#end
Now i am trying to add reference to my label. I go to LaunchScreen.xib and right click on the label. According to the tutorial, i have to see "answerField" and "questionField" under the "Outlets" tab, but nothing shows up. Can anyone tell me why this can be happening?
Thanks

A few things:
1) That code should really be in a view controller and not the application delegate
2) You probably should be looking in the Main.storyboard file and not LaunchScreen.xib
3) Make sure that File's Owner is set to the correct view controller on Main.storyboard after you move that code into a view controller.

Related

iOS custom UIView access properties in code

So I've created a custom UIView subclass and have it assigned to a UIView in my main storyboard. When the view loads everything is displayed properly.
The issue I'm having is that I need to be able to access properties of said custom UIView since the view is data driven.
JSON_table.h:
#import <UIKit/UIKit.h>
#interface JSON_table : UIView
#property (strong, nonatomic) IBOutlet UIView *view;
#property (weak, nonatomic) IBOutlet UISearchBar *searchbar;
#property (weak, nonatomic) IBOutlet UITableView *table_view;
#property (weak, nonatomic) NSString *data_header;
#property (weak, nonatomic) NSString *data_list;
#end
JSON_table.m:
#import "JSON_table.h"
#implementation JSON_table
- (id) initWithCoder:(NSCoder *)aDecoder{
self = [super initWithCoder:aDecoder];
if (self) {
[[NSBundle mainBundle] loadNibNamed:#"JSON_table" owner:self options:nil];
[self addSubview:self.view];
}
return self;
}
#end
(I know I'm missing delegates for tableview, ill be adding these later)
The issue I'm having is when I right click on my UIView on my storyboard I get:
The problem is when I try to connect "view" to my header file "
ViewController.h" it doesn't let me create a IBOutlet, so I cannot reference my view and its properties in code.
This is what I am trying to accomplish:
"Table" is of type UIView
Idea:
Would this have anything to do with the UIView being on the second view in my storyboard? I noticed that I don't seem to have any problem attaching to anything on the first page, but the second one I can't.
You can only connect the outlets of a view to it's class object. You are trying to connect outlets of JSON_table object to UIViewController object.
If you need to access those properties in UIViewController object. You need to import
JSON_table.h
in your view controller. And create and instantiate a object of it.
JSON_table * customView = [[JSON_table alloc]init];
Now you can access all the properties of it as:
customView.searchbar, customView.view etc.
Added by theshadow124:
Thanks to everyone who attempted to help me solve my problem. Due to being fairly new to coding for iOS I didn't realize I had to assign a custom class to every UIViewController in my storyboard(I thought they they would inherit from the base if I didn't specify). simply creating a new subclass of UIViewController and assigning it under the Identity inspector fixed my problem and now I can properly assign outlets.
Im going to accept this answer because it was one of the issues I ran into after fixing the subclass on the storyboard issue.
Please make sure that in assistant editor your are opening the same class that your custom class is contained in .

merge iAD within another view / definition

i am having trouble merging iAD into my current code/definition. i already have code set for a card scroll view style display and wanted to add iAD to the same view controller:
how can i do that without getting the errors i am getting?
this is the code for card scroll view in view controller.h
#interface ViewController1 : UIViewController <CardScrollViewDelegate>
#end
this is my code for iAD for view controller.h but should be merged with the above otherwise i get another error saying duplicate definition:
#interface ViewController1 : UIViewController <ADBannerViewDelegate> {
SLComposeViewController *mySLComposeSheet;
}
#property (weak, nonatomic) IBOutlet ADBannerView *banner1;
The view controller name / custom class im trying to add them both to is ViewController1
UPDATE:
its much simpler than i thought, just add a comma (FOR THOSE WHO ARE CURIOUS LIKE I WAS)
#interface ViewController1 : UIViewController <CardScrollViewDelegate, ADBannerViewDelegate> {
}
#property (weak, nonatomic) IBOutlet ADBannerView *banner1;
#end
Your code and/or question is ambiguious. I see 3 view controllers and 2 delegates. Eitherway...which viewcontroller are you trying to add it to? Whichever one it is. Inside the implementation file should be the following:
Remember to import iAd and your code should look like this:
#import <iAd/iAd.h>;
#interface ViewController1 : UIViewController <ADBannerViewDelegate>
{
ADBannerView *banner1;
BOOL bannerIsVisible;
}
#property (nonatomic,assign) BOOL bannerIsVisible;
Then, in viewDidLoad you can load it in a frame etc...

How can I manipulate objects in a subView?

Got away from XCode programming for a while, now I'm starting back and feel like I'm starting ALL over. I have a simple example that's driving me crazy.
I have created a sub class of UIView called Word1View and added it to my storyboard.
I declared it as a property in the main view controller and attached it as an IBOutlet to the main view. I can draw on this view using Core Graphics with no problems (rectangles, lines, etc). Here's the code in the ".h" file. The property is synthesized correctly in the ".m"
#import <UIKit/UIKit.h>
#import "Word1View.h"
#interface Board3ViewController : UIViewController
{
Word1View *word1View;
}
#property (nonatomic, strong) IBOutlet Word1View *word1View;
#end
Now, here's the problem. I have added a UILabel (I will be adding UIImageFiles later)
in Word1View.h it appears as so:
#import <UIKit/UIKit.h>
#interface Word1View : UIView
{
UILabel *testLabel;
}
#property (nonatomic, retain) UILabel *testLabel;
#end
This property is also synthesized correctly. The UILabel was added to the view in the main storyboard. I tried to make this an IBOutlet, but could not hook it up as long as it was part of the subview. I tried to access the UILabel in my main view controller as so:
[super viewDidLoad];
[self.view addSubview:word1View];
NSLog(#"Label text is: %#", word1View.testLabel.text);
I don't have any access to that label as evidenced by the output to NSLog which is:
Board3[14520:c07] Label text is: (null)
I would like to be able to access the label (change its text, properties etc) from my main View Controller.
Any help is greatly appreciated. Thank you.
You need to instantiate your UILabel and give it some text.
wordView1 = [[UILabel alloc] init];
wordView.text = #"Some Text";

Why are all IBOutlets set except _view?

I get the famous loaded the "MyController" nib but the view outlet was not set error. However I made sure, that the IBOutlet view is set.
Once the exception is thrown I hit a breakpoint. Below you can see that
All IBOutlets are connected
All IBOutlets are set
When unfolding UIViewController super-class, I can see that _view is 0x00000000 and obviously causes this exception.
Code (header)
#interface InfoDialogViewController : UIViewController
#property (strong, nonatomic) id episode;
#property (strong, nonatomic) NSString *identifier;
#property (strong) IBOutlet UIView *regularSide;
#property (strong) IBOutlet UIView *flippedSide;
#property (weak) IBOutlet UIImageView *episodeCover;
#property (weak) IBOutlet UITextView *episodeTitle;
#property (weak) IBOutlet UITextView *episodeSummary;
- (IBAction)flip:(id)sender;
#end
Some notes
The xib file contains three UIViews on its root level (Flipped, Regular, View)
InfoDialogViewController.m file doesn't contain any methods (I don't do any funky by overriding)
I am using this Controller in combination with addChildViewController.
Anybody has an idea what happens here and how I can fix it? Does ARC play some tricks on me?
Please check:
1. The Class for your View Controller's View should be UIView
2. File owner should be your View Controller
3. Right CLick on File Owner, your view Outlet should be set.
If it is already solved, can u mention what solved your issue?

ViewController containing UIView which is a MKMapView

I have a view controller and I want part of it to be a UIView which I would put custom UIViews that I've created in and change them throughout the run of the app.
I have my view controller and in the storyboard I put in it a UIView.
I created a custom UIView that has a MKMapView:
#interface MapUIView : UIView <CLLocationManagerDelegate,MKMapViewDelegate> {
CLLocationManager *locationManager;
}
#property (weak, nonatomic) IBOutlet MKMapView *mapCtl;
#property (strong, nonatomic) IBOutlet UILabel *address;
#property (nonatomic,strong) CLGeocoder *reverseGeo;
#end
Now what I want to do is to set the UIView in the main view controller to my custom UIView and that it will show a MKMapView.
I'm kind of new to this, so if you see anything wrong with my implementation please correct me.
Select the view, then select the identity inspector in the utilities panel on the right-hand side. You can change it to be a custom subclass of UIView there.
Note that simply creating a MKMapView property on the view doesn't actually create an instance of MKMapView or add it as a subview, so you'll need to either do that programmatically or by adding it in the storyboard.

Resources