Possible to link .xib to class written within a class? - ios

I like to keep my code clean and I have multiple classes written for custom cells right now. Most of those cells are used in only 1 UITableView.
So lets say we have the classes CustomUITableViewController and CustomUITableViewCell. What I'm looking for is something along these lines in the CustomUITableViewController.
#interface CustomUITableViewController()
//stuff
#end
#interface CustomUITableViewCell : UITableViewCell
//stuff
#end
#implementation CustomUITableViewCell
//stuff
#end
#implemention CustomUITableViewController
-(UITableViewCell*)cellForRowAtIndexPath... {
CustomUITableViewCell *cell = dequeueCellFor...
return cell;
}
-(void)viewDidLoad {
[super viewDidLoad]
//this next line should be right?????
[self.tableView registerNib:nib forCellReuseIdentifier:#"CustomCell"];
}
#end
Is my viewDidLoad method correct? I should write it just like I would if I was writing the UITableViewCell in a separate file?
What do I put in the .xib file? When I try to change the class to a custom class it doesn't link up with CustomUITableViewCell, and of course it doesn't match up with CustomUITableViewController (although I tried anyways.)

Yes.
What do you mean by 'doesn't link up with CustomUITableViewCell'? As long as your nib object is the nib for your custom cell, and in the xib for that cell the root object is a UITableViewCell with its custom class property set to your CustomUITableViewCell type you should be good to go. I've used this approach myself, although I've found that putting logic in the cells is more pain than it's worth.
On a side note, you should be sure to use a three letter prefix with all your classes to avoid collisions with Apple private classes.
The "Not KVC compliant" error is usually caused by one of two things in this situation:
1) You modified the XIBs but Xcode didn't notice the change and so didn't deploy the modified file. This usually occurs when you change something like the cell identifier in the XIB. Delete your app from the simulator/device and try running again.
2) You had properties declared on the custom class for the cell (or possibly something else unrelated in the view hierarchy) that were connected in IB at one time, but you've since changed the class behind IB's back and it doesn't know that it shouldn't try to make those connections again. Right-click each view in the scene to look for any broken connections and remove them. This happens to me if I correct the spelling of a property or change it in any way and don't remove and re-add the connection in IB. 95% of the time, this is the problem when I see that error.

Related

Multiple Class in one file

Recently I was studying the possibility of creating multiple classes in only one file, for this I created a class of UIViewController with a .xib file, the structure of the file is as follows:
MyFristViewController.h
#import <UIKit/UIKit.h>
#interface MyFristViewController : UIViewController
#end
#interface MySecondViewController : UIViewController
#end
MyFristViewController.m
#implementation MyFristViewController
- (void)viewDidLoad {
[super viewDidLoad];
NSLog(#"Frist View Loaded");
}
#end
#implementation MySecondViewController
- (void)viewDidLoad {
[super viewDidLoad];
NSLog(#"Second View Loaded");
}
#end
My doubt is: How does the system know that is to perform the methods contained in the class called 'MyFristViewController'?
I already tried to modify the custom class in interface builder, tried to change the position of the classes in the file and the system continues running only the existing methods inside the 'MyFristViewController' class why?
How does the system know that is to perform the methods contained in the class called 'MyFristViewController'?
The filenames are irrelevant. When looking at a class, for the most part, the code between #implementation <#ClassName#> and #end is used.
Additional customization of classes can be added through categories and class extensions. These can also be specified in the same file, or different files, because (again) the filenames are irrelevant.
Generally, you should have one class per file to make it easy to read and find your code. See How many classes should a programmer put in one file? for additional discussion.
My doubt is: How does the system know that is to perform the methods contained in the class called 'MyFristViewController'?
Because the methods are in the #implementation block of MyFristViewController.
I already tried to modify the custom class in interface builder, tried to change the position of the classes in the file and the system continues running only the existing methods inside the 'MyFristViewController' class why?
Probably because you've linked them to the methods in first #interface section in your header file. Control-drag to the actual method you want to bind to. It's not clear what problem you're actually seeing.
That said, this is a terrible idea. Put each view controller in its own file. It'll work in one file, but it will create lots of confusion, as you're seeing.
I have worked on projects that define multiple classes in a single file. I loathe this practice. I find it very disorienting and I waste a lot of time searching for where the classes are defined/implemented.
I would advise you not to do this. It ends up being very confusing.

How can I add Apple's source code for UITableViewCell to my project?

Before you tell me that all I need to do is import UIKit, I know all about importing, and NO, that's not what I need to do in this case. Intrigued? Confused? Read on...
I have two different, but similar, custom UITableViewCells. Both have a UILabel and a UISwitch. Version one, DisplayCell, has a second UILabel, while version two, EditCell, has a UIPickerView. How I use them is like this, in a static UITableView that I'm using as a fill-in-the-data form, DisplayCell is the standard view which displays the selected value. The user can tap on DisplayCell to replace it with EditCell, then use the UIPickerView to pick a new value and hit done (button in the nav bar at the top). DisplayCell is then brought back, displaying the newly selected value. In either version the user can tap the switch to toggle whether or not the value from the UIPickerView should be used elsewhere in the form.
When it came time to write the code for the tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> (UITableViewCell) function I decided to rewrite my code so that I have a single class, SwitchCell that inherits from UITableViewCell and contains the IBOutlet and IBAction for the switch, then have DisplayCell and EditCell inherit from SwitchCell.
This works fine, however DisplayCell is now nothing more than a IBOutlet for a UILabel, and UITableViewCell, which DisplayCell inherits from via SwitchCell already has two UILabel IBOutlets, textLabel and detailTextLabel. The whole purpose in creating SwitchCell was to try and minimize code by only ever write any block of code once, something that I'm a bit of a fanatic about. Thus I would very much rather have the UILabel in DisplayCell use the detailTextLabel IBOutlet from UITabelViewCell, rather than having to create a 'redundant' UILabel IBOutlet for it.
In order to link to an IBOutlet in a superclass you must be able to bring up the code for that superclass in the assistant editor. Then you can just control+drag and link like normal. Which means, in theory, I believe it should be possible to link my UILabel to UITableViewCell's detailTextLabel, if I can access the appropriate line from the source code for UITableViewCell in the assistant editor. Is this possible, and if so, how?
Oh, and I'm working exclusively in Swift in this project, FYI.
tl;dr: It's really not anymore efficient to use UITableViewCell's default UILabels than it is to just add your own.
In order to link to an IBOutlet in a superclass you must be able to bring up the code for that superclass in the assistant editor.
Well, that's not correct. The assistant editor is not required to link to an IBOutlet defined in a superclass. But that's not important here anyway.
You can't link to detailTextLabel in Interface Builder because it's not defined with the #IBOutlet attribute. And although it is possible to override properties in Swift (so you can add #IBOutlet to it), that won't work in this case because an IBOutlet has to be mutable, and the superclass has defined the variable as immutable.
Now you could overcome this by adding your own setter method in the subclass to make the property mutable. I was able to do this with the following code:
var _detailTextLabel: UILabel?
#IBOutlet override var detailTextLabel: UILabel? {
get {
return super.detailTextLabel
}
set {
_detailTextLabel = newValue
}
}
I could wire this up in Interface Builder just fine. So perhaps I could tweak this code to actually get an set what I want (I don't think it would work as shown here). We're so far outside the realm of common-sense coding that we just need to stop and give up on this idea.
Thus I would very much rather have the UILabel in DisplayCell use the detailTextLabel IBOutlet from UITabelViewCell, rather than having to create a 'redundant' UILabel IBOutlet for it.
I can relate. I'm just as anal. :-)
However, if you do a little testing (or read the UITableViewCell header file) you'll see that UITableView is smart enough (optimized enough?) to not actually add a UILabel to the content view unless you try to use it. So at worst you have an unused property.
So it's really not inefficient to just add your own UILabel and property.

Navigation Controller from Storyboard to XIB? Coding for table cells not working on Storyboard? Use XIB?

I initially had a mostly-functioning app that I had some hang-ups on. I was trying to use XIB files to do specific coding for things like Scrollers and Tables. The issue came when I tried to navigate back from the XIB to the Storyboard it was being presented from. I posted about my issue on another site and found out I was not navigating within my app correctly because I was not using a Navigation Controller.
I started over on the app and now I have my Navigation controller issues taken care of. The app looks much better. Now I have come to an issue that led me to all of this in the first place. I'm trying to do a few more complex pages in the app involving tables, scrolling, and map functionality. It seems as though certain code that I try to do can only be executed properly when I build the view in a new XIB file. If I try the same code in an .h or .m file for a View Controller on my Storyboard and just apply the class to it, I will get errors I don't understand. For some things, it seems to work fine. Pushing views with buttons, and redirecting to YouTube/Safari all work just fine. I know all about classes, defining actions and coding them in the .h and .m files, so I know the code is going to the right place. If I try anything with tables or scrollers, it seems to only work within a XIB.
I'm trying to do a scrolling table view in one of my View Controllers on the storyboard. I've tried using a View Controller with a table view inside of it, as well as a straight-up Table View Controller. Neither of the methods I have tried worked properly. The basic template works fine, but the minute I try to do any coding with it I get shut out. I watched several YouTube tutorials, and both of the methods I have tried threw up errors and crashed the app on that View Controller.
I had similar problems creating a scroll view. This is what let me to make my views in XIBs originally, as it seems the code works just fine with that method. But then I run into the problem of navigating from the XIB to a Storyboard, which is the problem I started with. I cannot seem to embed a Navigation Controller in the XIB and have it work properly in relation to the storyboard, that throws up more problems (which is why I was making my own Back button in the original post). I only tried it messing around, as I don't really know what I'm doing. I'm understanding some of it, through tutorials online, but then these very specific problems pop up that I can't find an answer to.
Most of these tutorials involve one or two View Controllers, and they're simple tutorials. Are there just some things you can only do from XIBs? Table Views, UIScrollView, nothing but problems. Everything else I do works fine, mainly just pushing views and redirecting to Safari, but still. If I can do everything in a Storyboard View Controller that I can do in a XIB view, it would make it a lot easier, but that doesn't seem to be the case. Am I wrong?
I guess the short way of saying this, is
1) Can I execute the same code in a Storyboard View Controller as I can in a XIB? Why do some things I try only seem to work if I have a separate XIB to design the view? (ex. UITableViewController UITableView)
2) Is it possible to work with XIBs and Storyboards seamlessly? I had trouble using a Navigation Controller in the XIB while also using one on the Storyboard. Is there a correct way to do this?
Sorry, I didn't have xCode up when I posted this so I was justing trying to be as specific as possible. I will try to explain what I'm doing currently so I can cut down on the clutter.
Here is the code from my ArtViewController.m, which is assigned to my View Controller with a table view within it:
{
NSArray *titleArray;
NSArray *logoFileArray;
}
#end
#implementation ArtViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
titleArray = [[NSArray alloc]initWithObjects:#"Frauenthal Center for Performing Arts",#"Muskegon Museum of Art",#"L.C. Walker Arena","Howmet Playhouse", nil];
logoFileArray = [[NSArray alloc]initWithObjects:#"",#"",#"","", nil];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return titleArray.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
ArtCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell)
{
cell = [[ArtCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.firstLabel.text = [titleArray objectAtIndex:indexPath.row];
cell.myImageView.image = [UIImage imageNamed:[logoFileArray objectAtIndex:indexPath.row]];
return cell;
}
And my ArtViewController.h has a property like this:
#property (weak, nonatomic) IBOutlet UITableView *artTableView;
Then I have my ArtCell.h (UITableViewCell) with this:
#property (weak, nonatomic) IBOutlet UIImageView *myImageView;
#property (weak, nonatomic) IBOutlet UILabel *firstLabel;
Here is my ArtCell.m, but I don't think I changed anything:
- (void)awakeFromNib {
// Initialization code
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
When I run the app, it crashes at the ArtViewController and gives me an error here:
titleArray = [[NSArray alloc]initWithObjects:#"Frauenthal Center for Performing Arts",#"Muskegon Museum of Art",#"L.C. Walker Arena","Howmet Playhouse", nil];
The error is THREAD 1: EXC_BAD_ACCESS (code=EXC_I386_gpflt).
You posted really long story, without providing any code samples that you have problems with. In short, then answers to your questions yes and yes.
Everything that you create/change in Storyboard or in XIB files you can also do directly from the code. It's not recommended way of course especially if you're planning to extended and support your application going forward. Some things are just easier to do in the Storyboards (like auto-layout constraints)
You also can mix and match Storyboard and XIB files. It's quite common to have main application layout and flow in the Storyboard and define individual complicated views or table cells in individual XIB files.
I would recommend for you to try and isolate your problems. If you think you're having issues with Table Views - create a sample project with one table view and simple data source. Make sure it works using Storyboard or direct code. Then see how you can apply your knowledge to the main project you're working on.
titleArray = [[NSArray alloc] initWithObjects:#"Frauenthal Center for Performing Arts",#"Muskegon Museum of Art",#"L.C. Walker Arena","Howmet Playhouse", nil];
The last string in your array, isn't. You don't have an # at the start of "Howmet Playhouse".
The first 95% of your question was irrelevant :)

Changing SearchDisplayController Delegate in interface builder

I'm trying to show a search bar above a table with a list of recent searches that will swap to matching search results once someone enters a search term.
I want to set a custom class MySearchViewController to be the delegate for doing the search and managing the display of search results back to the table so that I can separate the code and not have conditional statements in the default controller.
I've found a bunch of examples that describe how to do this in code but I can't figure out how to do it using Interface Builder.
I've tried dragging a new viewcontroller into my xib and setting the custom class to MySearchViewController and then dragging outlets from the SearchDisplayController as hinted at here: http://goo.gl/RgmwG
I've also tried dragging an Object into the objects column and changing this class to MySearchViewController.
But I feeling completely lost and really just trying things randomly. I'm guessing that I also need to create a property/IBOutlet for the SearchDisplayController somewhere but again lost.
If anyone has a reference to how to go about this I'd be so happy!
Like most problems, it seems pretty obvious in retrospect.
Add an 'object' placeholder in interface builder (orange cube).
Change the objects custom class to the class you want to be the delegate - e.g. MySearchViewController
Remove the default outlets from the standard SearchDisplayContoller to connect with the MySearchViewController object (see screenshot)
Make sure that the new delegate has an outlet to a parent view (in my case View)
Make sure that the delegate class is initiated from somewhere
// I did this from the parent ViewConroller, but probably better from the main app delegate?
#property (strong, nonatomic) IBOutlet MSSearchViewController *searchViewController;
Hope this helps someone else who was also stuck!

Loaded nib but the 'view' outlet was not set

I added a new nib file to my project, and tried to load it.
However, when I click on the toolbar icon that is supposed to take me to the view that I created, I get an NSInternalInconsistencyException with the message:
Terminating app due to uncaught exception
'NSInternalInconsistencyException', reason: '-[UIViewController
_loadViewFromNibNamed:bundle:] loaded the "..." nib but the view outlet was not set.'
So I opened up my nib file, and I see for the view that there are no referencing outlets set. However, I try to click and drag the circle for "new referencing outlet" to File's Owner, but it won't let me...what do I need to do to get my view to display?
Here's what worked for me:
Open the XIB file causing problems
Click on file's owner icon on the left bar (top one, looks like a yellow outlined box)
If you don't see the right-hand sidebar, click on the third icon above "view" in your toolbar. This will show the right-hand sidebar
In the right-hand sidebar, click on the fourth tab--the one that looks a bit like a newspaper
Under "Custom Class" at the top, make sure Class is the name of the ViewController that should correspond to this view. If not, enter it
In the right-hand sidebar, click on the last tab--the one that looks like a circle with an arrow in it
You should see "outlets" with "view" under it. Drag the circle next to it over to the "view" icon on the left bar (bottom one, looks like a white square with a thick gray outline
Save the xib and re-run
This is Josh Justice proposal, but in a graphical way (pictures are mine):
Select File owner
On right hand side panel select custom class.
Enter the custom class name
On right hand side panel select oultets
Drag view outlet to view component
Finally the View Controller is instantiated with the rolling code:
PTFilterUserVC *aFilterUserVC = [[PTFilterUserVC alloc] initWithNibName:#"FilterVC" bundle:nil];
//OPTIONAL.This is how 'I' am interested in present the view controller.
[self.navigationController pushViewController:aFilterUserVC animated:YES];
I can generally fix it by remaking the connection between File's Owner and the view. Control-drag from the File's owner to your View (in IB) and select view from the pop-up menu.
The View Identity - Class Identity was not set. After setting it to the appropriate class, the issue was resolved.
Are you sure you have a UIView (or subclass) assigned to the "view" property of yourViewController?
Right click on "File Owner" in the left pane of the xib for yourViewController and verify that the "view" outlet is set.
If not, set it to a view!
this will definetly fix the Issue
For me all the things stated here https://stackoverflow.com/a/6395750/939501 were true but still it was throwing error, reason was I created a View class with name ABCView and then deleted it later I added a view controller as ABCViewController so somehow it was referring to old ABCView in new view controller, I had to delete the ABCViewController and add a new one with different name that solved my issue.
Thanks
I had the same issue with XCode 4.6.3. I had started out with a couple files named MySettingsView.h and .m but deleted them in favor of MySettingsViewController.h, but despite trying most of the hints mentioned here, it still kept erroring with,
2013-07-05 11:48:17.205 MyApp[39024:c07] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason:
'-[UIViewController _loadViewFromNibNamed:bundle:] loaded the
"MySettingsView" nib but the view outlet was not set.'
It was evidently still "confused", trying to load MySettingsView.xib instead of MySettingsView Controller.xib. Maybe its "do what I mean" logic is too fancy.
So I worked around the problem by hardcoding the NIB/XIB name in MySettingsViewController.m:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:#"MySettingsViewController" bundle:nibBundleOrNil];
}
I ran into this problem in a slightly different way from the other answers here.
If I simply created a new xib file, added a UIViewController to it in Interface Builder, and set that UIViewController's custom class to my view controller, that resulted in the "view outlet was not set" crash. The other solutions here say to control-drag the view outlet to the View, but for me the view outlet was greyed out and I couldn't control-drag it.
I figured out that my mistake was in adding a UIViewController in Interface Builder. Instead, I had to add a UIView, and set the Custom Class of the File's Owner to my view controller. Then I could control-drag the view outlet of the File's Owner to my new view UIView and everything worked as it should.
To anyone that is using an xib method to create a UIView and having this problem, you will notice that you won't have the "view" outlet under the connections inspector menu. But if you set the File's Owners custom class to a UIViewController and then you will see the "view" outlet, which you can just CMND connect an outlet to the CustomView.
My issue with this was caused by having a duplicate nib in the class folder that did not have the view set. xcode seemed to be choosing one nib for a build and then the other the next time I built the project. Just deleted the other one. Looks good. Doh!
Just spent more than hour trying to find out why my view property is not set in my view controller upon initiating it from nib. Remember to call "[super initWithNibName...]" inside your view controller's initWithNibName.
I just fixed this in mine. Large project, two files. One was "ReallyLargeNameView" and another was "ReallyLargeNameViewController"
Based on the 2nd answer chosen above, I decided I should clean my build. Nada, but I was still suspect of XCode (as I have two identical classes, should abstract them but eh...) So one's working, one's not. File's owner names are so far as copy and pasted, outlets rehooked up, xCode rebooted, still nothing.
So I delete the similar named class (which is a view). Soon, new error "outlet inside not hooked up" literally was "webView not key value" blah... basically saying "Visual Studio's better". Anyway... I erase the smaller named file, and bam, it works.
XCode is confused by similar-named files. And the project is large enough to need rebooting a bit, that may be part of it.
Wish I had a more technical answer than "XCode is confused", but well, xCode gets confused a lot at this point. Unconfused it the same way I'd help a little kid. It works now, :) Should benefit others if the above doesn't fix anything.
Always remember to clean your builds (by deleting off the simulator too)
The previous answers almost solved the problem for me, but the last step was missing.
Create a xib and swift file with the same name.
Set the file owner to be the UIView subclass.
Drag an outlet from the View to the UIView subclass, name it "contentView"
Add this custom initializer so when the xib loads it attaches the contentView
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
Bundle(for: self.classForCoder).loadNibNamed("SampleView", owner: self, options: nil)
addSubview(contentView)
contentView.frame = self.bounds
contentView.autoresizingMask = [.flexibleHeight, .flexibleWidth]
}
Now any #IBOutlets you add will be attached.
Cheers,
Richard
I also had the same problem and my issue was that i added an other Localisation (English) to the ViewControllers nib so my App with the Localisation German couldĀ“t find the nib with the Localisation English!! Hope this helps anybody!
I had face the same problem while accidentally deleted xib reference and added it again.I just fixed by making connection between Files owner and the view.Also make sure that your FilesOwner's custom class is your expected viewController.
For me, the problem was caused by calling initWithNibName:bundle:. I am using table view cells from a nib file to define entry forms that sit on tableViews. As I don't have a view, doesn't make sense to hook to one. Instead, if I call the initWithStyle: method instead, and from within there, I load the nib file, then things work as expected.
I had the same problem, but a slightly different solution was called for. The problem in this case was the class of the File Owner, rather than the class of the View. To set this, I had to click the "backwards play" icon in the lower left corner of the Interface Builder window, and options then appeared that isolated the characteristics of the File Owner, the First Responder, and the View. Clicking on the first one (a large transparent box), enabled me to then set its custom class as suggested above.
I had the same problem, but a different solution was called for. The problem in this case was the class of the File Owner was not connected to xib file.
I ran into something very similar tonight, with a Swift UIViewController subclass. In this case, none of the above fixes worked, but reordering my code a bit did. Net-net, having an extension to the subclass occur before the subclass's definition itself in the same file seems to confuse XCode, despite compiling fine; the fix was to place the extensions after the subclass's definition.
I've posted the details in an answer to this similar question.
In my case , the designated initializer - (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil in ***ViewController class was implemented so even if when I call other initializer to initialize the object ,the designated initializer will be called .
So to resolve this problem checking wether the - (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil is also a proper way.
My problem was in wrong classes. I used custom .xib for my custom view.
Correctly it has to be set like here:
View shouldn't have a class
Class which is used with the .xib is set in File's Owner tab
Outlets are connected to File's Owner and not to the View.
Just had the same error in my project, but different reason. In my case I had an IBOutlet setup with the name "View" in my custom UITableViewController class. I knew "view" was special because that is a member of the base class, but I didn't think View (different case) would also be a problem. I guess some areas of Cocoa are not case-sensitive, and probably loading a xib is one of those areas. So I just renamed it to DefaultView and all is good now.
select the files owner and goto open the identity inspecter give the class name to which it corresponds to. If none of the above methods works and still you can't see the view outlet then give new referencing outlet Connection to the File's Owner then you can able to see the view outlet. Click on the view Outlet to make a connection between the View Outlet and File's owner. Run the Application this works fine.
In my case, the view was not viewed in xib.
in xib the View was size = none (4th tab right hand). I set size to Freeform and reload xCode.
view was appealed and I set the proper link to View.
If you have tried everything and you still get this error, try re-creating the class file from scratch but remember to select the "Also create XIB file" check box. This will auto link up a few items that are not linked when creating these files separately. After this is created, you can likely cut and paste everything onto the new XIB and it should work fine.
I am finding this issue specifically with creating files separately in Swift.
for me it happened, when
I have a ViewController class ( .mm/h ) associated with the Nib file,
UIView from this ViewController has to be loaded on the another view as a subview,
we will call something like this
-(void)initCheckView{
CheckView *pCheckViewCtrl = [CheckView instance];
pCheckView = [pCheckViewCtrl view];
[[self view]addSubview:pCheckView];
[pCheckViewCtrl performCheck];
}
Where
+(CheckView *)instance{
static CheckView *pCheckView = nil;
static dispatch_once_t checkToken;
dispatch_once(&checkToken, ^{
pCheckView = [[CheckView alloc]initWithNibName:#"CheckView" bundle:nil];
if ( pCheckView){
[pCheckView initLocal];
**[pCheckView loadView];**
}
});
return pCheckView;
}
Here loadView was missing,,, adding this line resolved my problem.
I had the same problem, I figured out and it is because of i had ticked "Static cells" in the properties of Table View under Content option. Worked when it changed to "Dynamic Prototypes". Screenshot is below.
I had a similar problem with Xcode 9.3, and setting "Module" under the "File Owner's" attribute inspector to the project module fixed this for me.
Open your storyboard file where your viewController exists, or XIB related file with textEdit.app and check if the storyboard or XIB name is the same of your viewController, then change it, save and reload/restart Xcode.
If you're using a custom init method, check that you're returning something valid. I ran into a piece of code that crashed on something like this:
- (id)init {
self = [super init];
if (self) {
CustomController *controller = [[NSBundle mainBundle] loadNibNamed:NSStringFromClass(className) owner:self options:nil];
} return self;
}
In another class, the controller was created like so:
CustomController *controller = [[CustomController alloc] init];
The problem is that in the init method, self hasn't changed and should look like this instead:
- (id)init {
self = [super init];
if (self) {
CustomController *controller = [[NSBundle mainBundle] loadNibNamed:NSStringFromClass(className) owner:self options:nil];
[controller viewDidLoad];
self = controller;
} return self;
}

Resources