Reputation: 117
I am currently building a Profile Object that can return a view with all the information of the user. I want to be able to reuse the code in many different places so I am trying to build it in an NSObject but when I add it as a subview of my view, I cannot click the buttons. The buttons are created with a rectangle and then have a UILabel put on top of them. If I copy the cody where I am trying to put it, it works. I also tried creating a delegate but that did nothing either.
EDIT
UIView *profile = [[UIView alloc] initWithFrame:CGRectMake(10.0, 0.0, 300.0, 175.0)];
UIView *votesView = [[UIView alloc] initWithFrame:CGRectMake(60.0, 125.0, 60.0, 50.0)];
UILabel *votesLabel = [[UILabel alloc] initWithFrame:CGRectMake(5.0, 0.0, 50.0, 40.0)];
votesView.backgroundColor = [UIColor lightGrayColor];
votesLabel.text = votes;
votesLabel.textAlignment = UITextAlignmentCenter;
votesLabel.backgroundColor = [UIColor clearColor];
votesLabel.tag = 2;
[votesView addSubview:votesLabel];
[profile addSubview:votesView];
Upvotes: 0
Views: 176
Reputation: 6954
Why are you subclassing an NSObject, you can subclass an UIView and implement all your views that are to be included,
Also, I am not able to see how you are adding a button, I can see just labels in your code.
But would suggest that you need to mention action and target, where for target you can add your class where it is called
[btn addTarget:<class where you will add UIView returned by your class> action:<SEL in your class where you will add UIView> forControlEvents:<UIControlEvents>]
Upvotes: 1