I have a view controller CaptureDataVC
and a custom view KeyboardView
.
KeyboardView
has all the init functions required to work as needed:-(id)initWithCoder:(NSCoder *)aDecoder
and -(id)initWithFrame:(CGRect)frame
In CaptureDataVC
's xib file I have a UIView
with custom class KeyboardView
.
The view renders just fine. The problem is that I cannot call any of the methods in KeyboardView
(It compiles and I don't get any errors but the methods aren't called).
So basically I can't do this:
CaptureDataVC.h
@property (nonatomic,retain) IBOutlet KeyboardView *keyboardView;
CaptureDataVC.m
[self.keyboardView foo];
KeyboardView.m
-(void) foo {
NSLog(@"Hello World!"); //Won't print anyting
}
Any ideas ?
Edit:
The custom class is set to the blue view
Well, the first questions are:
[self.keyboardView foo];
line run? Put a breakpoint there.self.keyboardView
not nil? When the debugger has stopped on the previous breakpoint, type po self.keyboardView
in the debugger to check.A classic mistake is to assume that self.someView
is always set. Actually it won't, before view and outlets have been loaded. See the documentations of viewDidLoad
, and isViewLoaded
.
Please check if KeyboardView`s outlet property setup: if property is nil, nothing will happen
There is no need to initialize custom view manually as its added in view controller. All you have to do just check where you have been calling your custom view method. It should be called after your view loaded. i.e viewDidLoad or viewWillAppear method.
In CaptureDataVC.m
you must allocate the memory to object as:
self.keyboardView=[[KeyboardView alloc]init];
and the call your method as:
[self.keyboardView foo];
it will work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With