I have so far a simple application where when a TableViewCell is pressed, a custom class will be out on the screen. The class, Element, is derived from UIView, and draws two ImageViews and a Label programmatically, and it can be dragged around. These are the basic and important parts of the custom class:
And how I allocate/initialize it:
And I provided pictures for how I linked it, but I basically used an object, and gave it the class Element.
But the big problem is is that the links do not work. The couple NSLogs in touchesBegan only spit out (null). Have I set up my Element class wrong? Did I link it wrong? Or is it just Xcode4?
Much help would be greatly appreciated, and I hope I haven't wasted your time.
Also if it's worth anything, here's my parent tree:
The '|' representing a branch in the tree...
Anyways didn't know if it would make a difference.
Code:
// Element.h
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@class Element;
@protocol ElementDelegate <NSObject>
@required
- (void)elementWasTouchedWithName:(NSString *)name andID:(int)ID;
@end
@interface Element : UIView {
IBOutlet UIImageView *topPlacementCombo;
IBOutlet UIImageView *middlePlacementCombo;
IBOutlet UIImageView *bottomPlacementCombo;
IBOutlet UILabel *one;
IBOutlet UILabel *two;
IBOutlet UILabel *three;
}
@property (nonatomic, retain) IBOutlet UIImageView *topPlacementCombo;
@property (nonatomic, retain) IBOutlet UIImageView *middlePlacementCombo;
@property (nonatomic, retain) IBOutlet UIImageView *bottomPlacementCombo;
@property (nonatomic, retain) IBOutlet UILabel *one;
@property (nonatomic, retain) IBOutlet UILabel *two;
@property (nonatomic, retain) IBOutlet UILabel *three;
- (void)setDelegate:(id <ElementDelegate>)dlg;
- (void)loadVisualViews;
@end
Code:
//Element.m
#import "Element.h"
@implementation Element
@synthesize topPlacementCombo, middlePlacementCombo, bottomPlacementCombo;
@synthesize one, two, three;
- (void)setDelegate:(id <ElementDelegate>)dlg {
delegate = dlg;
}
- (id)init {
if((self = [super init])){
self.userInteractionEnabled = TRUE;
[self setBackgroundColor:[UIColor clearColor]];
}
return self;
}
- (void)loadVisualViews {
UIImageView *backgroundImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 64, 64)];
[backgroundImage setImage:[UIImage imageNamed:@"ElementBackground2.png"]];
[backgroundImage setOpaque:TRUE];
[self addSubview:backgroundImage];
[backgroundImage release];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 38, 64, 21)];
[label setBackgroundColor:[UIColor clearColor]];
[label setTextColor:[UIColor whiteColor]];
[label setAdjustsFontSizeToFitWidth:TRUE];
[label setTextAlignment:UITextAlignmentCenter];
[label setText:elementName];
[self addSubview:label];
[label release];
UIImageView *mainImage = [[UIImageView alloc] initWithFrame:CGRectMake(16, 5, 32, 32)];
[mainImage setImage:[UIImage imageNamed:@"SampleElementIcon2.png"]];
[mainImage setOpaque:TRUE];
[self addSubview:mainImage];
[mainImage release];
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
CGPoint pt = [[touches anyObject] locationInView:self];
startPosition = pt;
[[self superview] bringSubviewToFront:self];
[delegate elementWasTouchedWithName:elementName andID:elementID];
one.text = @"Blah";
NSLog(@"Text: %@", one.text);
[topPlacementCombo setHighlighted:TRUE];
NSLog(@"%@", topPlacementCombo.highlighted);
}
- (void)dealloc {
[super dealloc];
}
@end
And how I allocate/initialize it:
Code:
Element *element = [[Element alloc] init];
element.frame = CGRectMake(32, 32, 64, 64);
element.elementName = elementName;
[element loadVisualViews];
[self.boardView addSubview:element];
[element release];
And I provided pictures for how I linked it, but I basically used an object, and gave it the class Element.
But the big problem is is that the links do not work. The couple NSLogs in touchesBegan only spit out (null). Have I set up my Element class wrong? Did I link it wrong? Or is it just Xcode4?
Much help would be greatly appreciated, and I hope I haven't wasted your time.
Also if it's worth anything, here's my parent tree:
Window
ViewController View
UIView
3 UILabels | UIView
3 UIImageViews, UIButton
ViewController View
UIView
3 UILabels | UIView
3 UIImageViews, UIButton
The '|' representing a branch in the tree...
Anyways didn't know if it would make a difference.