UITableViewController loadView loaded nib but didn't get a UITableView. - ios

When I run my iOS simulator, I get this error:
UITableViewController loadView loaded the I1u-ML-mqb-view-QFc-WC-CU4 nib but didn't get a UITableView.'
My code:
#interface IF2000 : UITableViewController
#property (weak, nonatomic) IBOutlet UILabel *EnterCategory;
#property (weak, nonatomic) IBOutlet UITextField *Tfield;
- (IBAction)Submit:(id)sender;
#property (weak, nonatomic) IBOutlet UITableViewCell *EmptyCell;
#end
This is the only code that I have typed so far. If anyone knows how to solve this problem, I would appreciate the help. If I could get a general answer on how to solve this problem, that would be good as well.

Your nib file contains a view other than a table view as the first object. When you try to load a UITableViewController with a nib, you must make sure to have a table view as the first object.

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 .

Cannot find protocol declaration for 'FBLoginViewDelegate'

For some reason I'm getting the error Cannot find protocol declaration for 'FBLoginViewDelegate' when trying to include the FBLoginViewDelegate protocol to my ViewController interface.
I've searched for other similar questions but most of them seem to be related to circular inclusions...I don't think that's the case for me.
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController <UITextFieldDelegate, FBLoginViewDelegate>
//Properties
#property (weak, nonatomic) IBOutlet UITextField *txtPassword;
#property (weak, nonatomic) IBOutlet UITextField *txtEmail;
#property (weak, nonatomic) IBOutlet UILabel *lblResult;
- (IBAction)loginClicked:(id)sender;
- (IBAction)backgroundTap:(id)sender;
#end
I'm quite new to iOS development and any help would be greatly appreciated!
just remove and add the add the FacbookSDK and
make it
#import<FacbookSDK/FaceBookSDK.h> in your VC.h file or .pch file (the compiler takes the Facebook delegate in all VC's)
finally clean and run your project, it surely works

Which way of declaring IBoutlet is better

I was wondering which way is prefer for declaring an IBOutlet in a subview?
#property (weak, nonatomic) IBOutlet UITableView *mTableView;
or
IBOutlet UITableView *mTableView;
I believe the first one is better, but not too sure.
The first one is the better. Consider this : If you use the assistance editor and you Ctrl + Drag a view item straight into the code file, it will add it exactly like that
#property (weak, nonatomic) IBOutlet UITableView *mTableView;

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?

Changing outlet object properties

I have a view controller alertForNeedsClassification as a property in another class, as such:
#interface SCAAppDelegate()
{
HomeScreenViewController * _homeScreenViewController;
NSInteger SCAStatus;
}
#property (strong, nonatomic) PromptClassifyViewController * alertForNeedsClassification;
#end
#implementation SCAAppDelegate
#synthesize alertForNeedsClassification;
#synthesize window = _window;
PromptClassifyViewController's interface looks like this:
#interface PromptClassifyViewController : UIViewController
#property (weak, nonatomic) IBOutlet UILabel *headerTitle;
#property (weak, nonatomic) IBOutlet UITextView *message;
#property (weak, nonatomic) IBOutlet UIButton *notNowButton;
#property (weak, nonatomic) IBOutlet UIButton *classifyButton;
#property (weak, nonatomic) IBOutlet UIImageView *backgroundImageView;
#property (weak, nonatomic) IBOutlet UIView *alertView;
#property NSUInteger tag;
#property (weak, nonatomic) IBOutlet id<PromptClassifyViewControllerDelegate> delegate;
- (void)show;
- (void)showFromView:(UIView *)view;
- (IBAction)show:(id)sender;
- (IBAction)dismiss:(id)sender;
- (IBAction)buttonWasPressed:(id)sender;
- (void)setHeaderTitleWithText:(NSString *)text;
#end
I am trying to change the values of IBOutlets message and headerTitle text, like this:
alertForNeedsClassification = [[PromptClassifyViewController alloc] initWithNibName:#"PromptClassifyViewController" bundle:nil];
//[alertForNeedsClassification setDelegate:self];
self.alertForNeedsClassification.headerTitle.text = #"A title";
alertForNeedsClassification.message.text = #"A message";
Then I show alertForNeedsClassification calling a show method (it's like a custom uialertview, but it doesn't subclass from uialertview).
Thing is, no matter how I change it, the text on alertForNeedsClassification.view is always that which is defined in the nib, ie. I can't change it programmatically.
My custom alert view is based on Jeff LaMarche's design: http://iphonedevelopment.blogspot.com/2010/05/custom-alert-views.html
Any ideas what might be going on?
Please be careful when you allocate and initialize the UIView object, especially if you trying to mix using Nib and dynamically generating objects. The best place is within -(void)awakeFromNib or -(void)viewDidLoad
Also, make sure these methods are called. By using -(id)initWithNibName:bundle: only cannot make sure your view to be loaded. Try -(void)addChildViewController and -(void)addSubview: on parentViewController's view to make sure view is loaded after being initialized.
If the text had to be prepared before being loaded, assign it to separate NSString property within PromptClassifyViewController class. Since this property is independent from view being loaded, you can change it's value BEFORE view is appeared. Make sure this text is used and applied to the headerTitle within -(void)show method.
Since you allocate PromptClassifyViewController and access weak referenced headerTitle from self. alertForNeedsClassification, make sure it's not deallocated right afterward.
Usually, weak option is not used for IBOutlet properties. Though it is used when generating outlet connection code by dragging objects from Interface Builder. Try testing your code using strong.
I was assigning values to the IBOutlets before they were alloc'd/initialized. The solution I implemented was to set the values I needed to non-IBOutlet properties (NSStrings in this case) and assign those where needed, in Prompt...Controller's viewDidLoad;

Resources