This is so damn simple im sure! Im missing something and im exhausted from trying to fix it. hopefully someone can help.
The Button in CharacterView.m works but the
Does the new view accept user interaction? In other words, is userInteractionEnabled enabled on the view "Characters"?
FINALLY!!!!!!
I had to init all the views with initWithFrame and pass in valid frame rects. Init should be used with controllers and initWithFrame passing rects for UIViews!!!!
characterView = [ [ CharacterView alloc ] initWithFrame:CGRectMake(0, 0, 480, 320)];
then
characterMale = [ [ CharacterMale alloc ] initWithFrame:frame];
Another thing to consider is that UIButton
subviews that have been added a UIImageView
don't work at all. You need to create a UIView
that you add both the image view and the buttons to.
This is probably because interaction is turned off by default on image views, but I've not checked this.
I have had luck with a selector for a UIButton created in drawRect by using UIControlEventTouchDown
instead of the popular UIControlEventTouchUpInside
.
For me the issue was caused because, the origin of the button frame was bigger then the parent frame.
I had a similar issue when tried to add the button during the initialization of an UIView with a frame of CGRectZero:
@implementation SomeView
...
- (id)initWithTitleImage:(UIImage *) newTitleImage {
// BROKEN: frame with CGRectZero.
self = [super initWithFrame:CGRectZero];
if (self) {
UIButton *someButton = ...;
[self addSubview someButton];
}
}
Once I changed the frame to a proper rectangle, the button worked:
@implementation SomeView
...
- (id)initWithTitleImage:(UIImage *) newTitleImage {
// WORKING: frame with proper CGRect.
self = [super initWithFrame:CGRectMake(0, 0, 480, 320)];
if (self) {
UIButton *someButton = ...;
[self addSubview someButton];
}
}