#import <UIKit/UIKit.h>
#interface FourthViewController : UIViewController{
//#interface FourthViewController : UITableViewController{
I want to update my tableview so I trying to use [self.tableView reloadData] but i cannot even type this line of code since I'm working in a UIViewController and the tableView property is for UITableViewController's only. So I tried to be smart and just change the UIViewController to UITableViewController but instead i got this error:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UITableViewController loadView] loaded the "b4k-XH-Uhj-view-V2h-dE-ixJ" nib but didn't get a UITableView.'
Imo this is strange since a UITableViewController would work for a tableView but not the other way around, but seams like i got it all wrong, or whats happening here?
more code if you ask for it =)
Thanks ahead.
A UITableViewController is really just a UIViewController that contains an outlet to a UITableView and implements the two tableview delegates: UITableViewDelegate and UITableViewDataSource.
You may want to consider replacing the viewcontroller instance in your nib file with a UITableViewController rather than a standard UIViewController.
Alternatively, you can manually adjust your ForthViewController instance by creating an outlet for the contained UITableView to expose the tableview as a property.
However, if you do it this way you'll also have to manually implement the two tableview delegates UITableViewDelegate and UITableViewDataSource somewhere (probably in ForthViewController) and manually associate the UITableView with these delegates.
Related
I think this image explains it all. I have a subclass of UIView that I've entered into the class field. I'm trying to connect ibOutlets between the storyboard and class implementation. It's not giving me an error, but it's not working either. Is this another xcode bug, or am I expecting this to work in a way that it won't?
Here is a solution:
1) Type an IBOutlet by hands in your header file, example:
#property (strong, nonatomic) IBOutlet ProgressBarElementView *targetProgressElement;
2) Drag the pin from the code to the element in document outline zone
I have the same problem.. I saw that if you add the custom class to the root view in the view controller, it will work.. In your case this is the initial View, listed under Bottom Layout Guide
But there must be a better way
To overcome XCode stubborness, especially when you need to hook up different enums from UIControlEvent than UIControlEventTouchUpInside, I'd rather use code directly from within the custom view class:
SWIFT
button.addTarget(self, action:#selector(ClassName.handleRegister(sender:)),
for: .touchDragExit)
OBJECTIVE-C
[self.button addTarget:self
action: #selector(buttonTouchDragExitAction:)
forControlEvents:UIControlEventTouchDragExit];
One might include such code in awakeFromNib or viewDidLoad or where it best suits.
write the outlet inside your custom UIView
#IBOutlet weak var imageView: UIImageView!
then drag it into the storyboard on the view
I'm fairly new to Xcode and Cocoa development, so please excuse me if I use the wrong terminology.
I have a window which has an NSTableView bound to a NSArrayController. The NSTableView has some predefined columns and the NSArrayController is populated with data when my window is loaded.
This all works fine, but I now need to re-use the functionality in a number of other windows.
After much reading I think and NSViewController is what I need, to provide an object that I can re-use in different windows in multiple .xib.
So what I have done is created a new NSViewController sub class in Xcode which also created a new xib for that controller.
The xib contains a custom view, where I have placed my NSTableView.
#interface KeyViewController : NSViewController
#property (weak) IBOutlet NSTableView *keyTable;
#end
The files owner class is set to the KeyViewController, and the view outlet is set to the files owner.
I then placed a ViewController object into the original window and hooked up the view to a new custom view in the window
I then set the nib name for the ViewController in its properties.
The new view never gets displayed and the view controller initWithNibName never gets called.
Am I missing something vital or missing the plot completely. Should you be able to do this just with interface builder or do I need to alloc and init the view in code?
If I do have to do it in code, whats the purpose of the ViewController object in IB and the Nib Name property for it?
Thanks..
I have an mainUIView within which there is a customised UIImageView (named myImageView).
In the myImageView.h file, I have declared:
#property (strong, nonatomic) mainViewController *viewController;
and in the myImageView.m file, I have the following codes:
self.viewController = self.parent;
This lines raises an error indication:
Property 'parent' not found on object of type myImageView.
I thought putting the myImageView inside the mainUIView would make the default parent-and-sub relationship, but obviously it's not so.
In the main storyboard, I tried to Ctrl-drag the myImageView to the mainViewController, but no options pops up for me to select delegate.
Can anyone give me explanation of these please? I'm feeling a bit confused... Many thanks!
As your myImageView is a UIView is has no parent. Is just has a superview which again is a UIView. Basically a view doesn't know its controller. Although the controller can implement a view's delegate to get informed about events. So your AppDelegate knows your ViewController and the controller knows your ImageView. The AppDelegates window knows the view of your controller which will most likely contain the whole view hierarchy (except AlertViews, HUDViews, modal views and simmilar...).
I think what you want to do works best implementing the delegate pattern. (see Apple Docs)
I am new to iOS Development and am wondering how to put a scrollview in a storyboard, using Xcode 4.2. I want the content to be 1280 by 460. This code all works well, but when I go to wire up the outlet, there is no file's owner, so i'm stumped. Here is the code I have:
in the .h file-
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController {
IBOutlet UIScrollView *scrollView;
}
#end
and the .m, under viewDidLoad:
- (void)viewDidLoad
{
[scrollView setScrollEnabled:YES];
[scrollView setContentSize:CGSizeMake(1280,460)];
[scrollView setPagingEnabled:YES];
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
If anyone could help me, that would be great!
Storyboards do not have a File's Owner. You need to use the View Controller to connect the Outlets instead. I.E. Drag to the View Controller in the same way you used to drag to the File's Owner.
OK, I figured it out. I just had to create a class for my view controller. I was trying to use files that were not part of a class that was a subclass of UIViewController.I had to create a new class, then copy the old code in and make my view controller's class that of the NEW files, and THEN wire up the outlets. I was changing the class to something that was not there. I then wired my outlet up to the scroll view I wanted. Thankfully, that part is finally over! Thanks for the suggestions, guys, I really appreciate it.
A good visual tutorial is in the current Stanford CS193p course for iOS 5 in iTunes U.
This course works mainly with storyboards and they cover among other things UIScrollViews
What exactly is the point of adding a UIViewController in IB? There is no way to add code like you can if you create a viewController in Xcode? And if you can what is the advantage of doing it in IB.
And isn't the whole point of a MVC to seperate code into "modular" parts so why would add a ViewController in IB
Sometimes all you need is a UIViewController. But most times you would create a UIViewController subclass of your own (in IB).