Button hidden behind my BaseViewController in iPhone - iphone

I am facing weird problem. I have a baseViewController which extends with UIViewController.
in My BaseView controller i have a custom HeaderBar (UIImageView) on top of it.
I then made a new ViewController and extends that new ViewController with baseViewController. The headerBar in BaseViewController is appearing on my UIViewController. But now if I add any subview in my NEWViewController over that headerBar then it does not come over that whereas it goes behind the header bar.
Can anybody suggest what to do.
EDITED
Here is my code.
BASEViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
CGFloat xOffset = 0;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
xOffset = 224;
}
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
headerBarView = [self addHeaderBar];
//[self.view addSubview:headerBarView];
[self.view insertSubview:headerBarView belowSubview:self.view];
}
return self;
}
-(UIView *)addHeaderBar{
UIView *header_bar = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320, 50.0)];
//HeaderBar Image
UIImageView *headerBar = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0.0, 320, 50.0)];
[headerBar setImage:[UIImage imageNamed:#"top_bar"]];
[header_bar addSubview:headerBar];
return header_bar;
}
NEWViewController Extended With BaseViewController
//Back Button
back = [UI getActionBarButtonWithName:[NSString stringWithFormat:#"Back"] andCGRect:CGRectMake(7.0, 100.0, 55.0, 31.0) andEdgeInset:UIEdgeInsetsMake(0.0, 9.0, 2.0, 0.0) withBackGround:[UIImage imageNamed:#"back_button"]];
[self.view bringSubviewToFront:back];
+(UIButton *)getActionBarButtonWithName:(NSString *)name andCGRect:(CGRect)rect andEdgeInset:(UIEdgeInsets)edgeInset withBackGround:(UIImage *)background{
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = rect;
[button setBackgroundImage:background forState:UIControlStateNormal];
[button setTitleEdgeInsets:edgeInset];
[button setTitle:name forState:UIControlStateNormal];
[button.titleLabel setFont:[UIFont boldSystemFontOfSize:13.0]];
[button setUserInteractionEnabled:YES];
return button;
}

if you are having many views, you can also use any one of these -
[self.view insertSubview:<#(UIView *)#> aboveSubview:<#(UIView *)#>]
[self.view insertSubview:<#(UIView *)#> atIndex:<#(NSInteger)#>]
[self.view insertSubview:<#(UIView *)#> belowSubview:<#(UIView *)#>]
hope it will help you.

Try using
[self.view bringSubviewToFront:button];

New UIVIew override your base viewcontroller,you can set frame of new view and then add subview.
Ex. UIView* tempView=[UIView alloc]initWithFrame:CGRectMake(0,44,320,420)];
[self.view addSubView:temView];

Related

How to change NavigationBar of NavigationController in every other controller based on requirement?

In my app i have created a Custom UINavigationBar in which i have written different methods for customizing the UInavigationBar like navigation bar with title image, backbutton and signoff button some of them will only have two of these and some of them only title image.
I have to change the navigation bar based on which viewcontroller we are in.
Here's my CustomUINavigationClass
#import <UIKit/UIKit.h>
typedef enum {
simple = 1,
back,
signoff,
both
} NavBarChoices;
NavBarChoices optionSelect;
#interface CustomNavigationBar : UINavigationBar
{
UIBarButtonItem * menuButton;
UIButton * showEditButton;
}
- (id)initWithFrame:(CGRect)frame andOption:(NavBarChoices)choice;
#end
.m
#import "CustomNavigationBar.h"
#implementation CustomNavigationBar
- (id)initWithFrame:(CGRect)frame andOption:(NavBarChoices)choice
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
NSArray *arrayOfViews = [[NSBundle mainBundle] loadNibNamed:#"CustomNavigationBar"
owner:self
options:nil];
if ([arrayOfViews count] < 1){
return nil;
}
optionSelect = choice;
CustomNavigationBar *newView = [arrayOfViews objectAtIndex:0];
self = newView;
}
return self;
}
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
switch (optionSelect) {
case 1:
[self drawSimpleNavBar];
break;
case 2:
[self drawWithBackOnly];
break;
case 3:
[self drawWithSignOffOnly];
break;
case 4:
[self drawWithBackAndSignOff];
break;
default:
break;
}
}
-(void)drawSimpleNavBar {
self.tintColor = [UIColor whiteColor];
self.backgroundColor = [UIColor whiteColor];
UIImage *image = [UIImage imageNamed:#"title_logo.png"];
[image drawInRect:CGRectMake(100, 13, 104, 20)];
UIImage *menuImage = [UIImage imageNamed:#"menu_off.png"];
showEditButton = [UIButton buttonWithType:UIButtonTypeCustom];
showEditButton.bounds = CGRectMake(0, 0, menuImage.size.width, menuImage.size.height+10);
showEditButton.frame = CGRectMake(2, 10, menuImage.size.width, menuImage.size.height);
[showEditButton setImage:menuImage forState:UIControlStateNormal];
[showEditButton setImage:[UIImage imageNamed:#"menu_on.png"] forState:UIControlStateSelected];
[showEditButton addTarget:self action:#selector(showMenu) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:showEditButton];
}
-(void)drawWithBackOnly {
self.tintColor = [UIColor whiteColor];
self.backgroundColor = [UIColor whiteColor];
UIImage *image = [UIImage imageNamed:#"title_logo.png"];
[image drawInRect:CGRectMake(100, 13, 104, 20)];
UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
[backButton setTitle:#"Back" forState:UIControlStateNormal];
[backButton setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
backButton.frame = CGRectMake(0, 3, 80, 30);
backButton.titleLabel.font = [UIFont boldSystemFontOfSize:12];
[backButton sizeToFit];
[backButton addTarget:self action:#selector(back) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:backButton];
}
-(void)drawWithSignOffOnly {
}
-(void)drawWithBackAndSignOff {
}
-(void)showMenu {
NSLog(#"Clicked");
showEditButton.hidden = YES;
[showEditButton setImage:[UIImage imageNamed:#"menu_on.png"] forState:UIControlStateNormal];
}
#end
And i am calling this as in App Delegate :
navigationBar = [[CustomNavigationBar alloc]initWithFrame:CGRectMake(0, 0, 320, 44) andOption:simple];
UINavigationController * nav = [[UINavigationController alloc]initWithNavigationBarClass:[navigationBar class] toolbarClass:nil];
self.viewController = [[FirstViewController alloc] initWithNibName:#"FirstViewController" bundle:nil];
[nav setViewControllers:#[_viewController] animated:NO];
self.window.rootViewController = nav;
Now i have a button in First view controller on click i want to push another view conroller which will sent a request to the CustomNavigationBar class to change the navigation bar for the same NavigationController.
Please guide, currently i am trying to make changes to the viewDidLoad method of the new controller but the challenge is NavigationBar property of UINavigationController is readonly so can't assign new navigation bar to it or else i would have done something like this
CustomNavigationBar * navBar = [[CustomNavigationBar alloc]initWithFrame:CGRectMake(0, 0, 320, 44) andOption:2];
self.navigationController.navigationBar = navBar;
Please help.
Thanks,
Have you define the NIB and Class name in xib utilies?. if so confirm that class name and NIB name is same or not , Hope it will work in this situation

Programmatically created button not firing event in custom view in iOS

On iOS, I created a button programmatically but the event is not firing.
UIButton * anyButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[anyButton addTarget:self action:#selector(handleAnyButton:) forControlEvents:UIControlEventTouchUpInside];
anyButton.frame = CGRectMake(150, 350, 22, 22);
[self addSubview:anyButton];
The code is placed inside a custom view (not custom view controller), but I cannot make it fire the event. The press animation is not showing. The custom view has userInteractionEnabled enabled. I also tried using storyboard to create another button on the same view and that one is working. The button code is done in initWithFrame. Must be some simple error I haven't caught and I have been pounding my head over this one for hours.
EDIT:
The event handler:
-(void) handleAnyButton:(UIButton *)button
{
NSLog(#"handleAnybutton called");
}
EDIT2:
The above button codes is done within a [self setup] of class PKLocationsSelectionView.
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
[self setup];
}
return self;
}
And this view was created programmatically within the view controller (PKLocSelectionViewController) responsible for this hierarchy:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
CGFloat fieldsHeight = 88;
UIView * view = [[PKLocationsSelectionView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, fieldsHeight)];
[self.view addSubview:view];
}
It looks like your button frame
anyButton.frame = CGRectMake(150, 350, 22, 22);
is outside of parent bounds
CGFloat fieldsHeight = 88;
UIView * view = [[PKLocationsSelectionView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, fieldsHeight)];
Here is the code that works for me:
MyCustomView.m:
#import "MyCustomView.h"
#implementation MyCustomView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(0, 0, 100, 100);
[button addTarget:self action:#selector(greet:) forControlEvents:UIControlEventTouchUpInside];
[button setTitle:#"Greet" forState:UIControlStateNormal];
[self addSubview:button];
self.backgroundColor = [UIColor greenColor];
}
return self;
}
-(void) greet:(id) sender
{
NSLog(#"greet!");
}
And here is the ViewController.m:
- (void)viewDidLoad
{
[super viewDidLoad];
MyCustomView *view = [[MyCustomView alloc] init];
view.frame = CGRectMake(0, 0, 100, 100);
[self.view addSubview:view];
}
EDIT2: Could it be the Button is not fully enclosed within the coordinates of the container (PKLocationsSelectionView) view?
The height of the PKLocationsSelectionView is 88 from your code and the position of the button seems to be outside this. I think if the button is not enclosed within the frame of the superview then it won't receive touches.
Try and change your View initialization code in viewDidLoad, to give a static frame and see if it works..
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
CGFloat fieldsHeight = 88;
//See the change in below line.. instead of using self.view.bounds.size.width
// I used a static width.. 320 pixel for the moment..
UIView * view = [[PKLocationsSelectionView alloc] initWithFrame:CGRectMake(0, 0, 320.0, fieldsHeight)];
[self.view addSubview:view];
}
In viewDidLoad view hierarchy of controller will not be drawn completely..So self.view.bounds.size.width may be giving incorrect values.. To access self.view.frame and self.view.bounds, you should atleast wait until viewWillAppear gets called.
Also, your button origin.y is at 350 which in a view which has maximum height of only 88.. Any control outside parent's frame won't receive touches..

Simple Custom UIView Class Broken

I have made a simple subclass of UIView which has a few subviews but its breaking for a reason I can't see.
In my storyboard view controller I have added a UIView and made it the shape I want it, and added my custom class to it. The contents of my subclass is below:
#implementation PersonDetailCell
#synthesize button, requiredMarker, textField;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
-(void)layoutSubviews
{
[self setBackgroundColor:[UIColor colorWithRed:87.0f/255.0f green:153.0f/255.0f blue:191.0f/255.0f alpha:1.0f]];
textField = [[DetailTextField alloc] initWithFrame:CGRectMake(10, 0, self.frame.size.width -20, self.frame.size.height)];
[textField setFont:[UIFont fontWithName:#"Helvetica" size:14.0f]];
[textField setTextColor:[UIColor whiteColor]];
[textField setHidden:YES];
[self addSubview:textField];
button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
[button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[button setHidden:YES];
[self addSubview:button];
requiredMarker = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 4, 22)];
[requiredMarker setBackgroundColor:[UIColor redColor]];
[requiredMarker setHidden:YES];
[self addSubview:requiredMarker];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
// Drawing code
}
*/
#end
Then in my view controller code I have imported my subclass and hooked up an IBOutlet of it to my view in my storyboard. In my viewDidLoad of my view controller I also try setting background colour of this view but nothing happens.
All of my code runs without crashing, but my issues:
I can't set the background colour from my view controller, (or any other properties for that matter).
When I run the app, the height is more than that I set in my storyboard (width is fine), but I change the height of the view nowhere.
Any ideas? Am i using the wrong approach somehow?
Thanks.
If it is a table cell, then the class should be extending UITableViewCell. Buttons and textfields can be added on the storyboard - then you can use struts and springs (Size Inspector pane) to ensure the view resizes properly. I don't think layoutSubviews should be used for adding new UI elements (maybe for resizing if you need to do it manually).
Here is some working code:
#interface ChildView()
#property (strong, nonatomic) UITextField *textField;
#property (strong, nonatomic) UIButton *button;
#property (strong, nonatomic) UIImageView *requiredMarker;
#end
#implementation ChildView
#synthesize textField= _textField;
#synthesize button = _button;
#synthesize requiredMarker = _requiredMarker;
-(id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (self)
{
[self setBackgroundColor:[UIColor colorWithRed:87.0f/255.0f green:153.0f/255.0f blue:191.0f/255.0f alpha:1.0f]];
self.textField = [[UITextField alloc] init];
[self.textField setFont:[UIFont fontWithName:#"Helvetica" size:14.0f]];
[self.textField setTextColor:[UIColor whiteColor]];
self.textField.text = #"Test text";
[self addSubview:self.textField];
self.button = [[UIButton alloc] init];
self.button.backgroundColor = [UIColor greenColor];
[self addSubview:self.button];
self.requiredMarker = [[UIImageView alloc] init];
[self.requiredMarker setBackgroundColor:[UIColor redColor]];
[self addSubview:self.requiredMarker];
}
return self;
}
-(void)layoutSubviews
{
CGSize hostSize = self.frame.size;
float length = 22;
self.textField.frame = CGRectMake(10, length, hostSize.width, hostSize.height-length);
self.button.frame = CGRectMake(0, 0, hostSize.width, length);
self.requiredMarker.frame = CGRectMake(0, 0, 4, length);
}
#end

Trouble with autoresizingMask and fixed margins

I'm trying to get this to work with code in a ViewController's view:
but I can't get it to work.
I've tried
-(void)loadView {
UIView *contentView = [[[UIView alloc] init] autorelease];
self.view = contentView;
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(5,5,0,100);
button.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[contentView addSubview:button];
}
but the width of the button is still the width of the superview...
I'm sure there's an easy explanation.
Thanks, everybody!
Antonio
-initWithFrame: is the designated initializer for UIView. On the Mac side (NSView) I know strange things can happen when using -init instead of -initWithFrame:. Perhaps this is the problem?
Instead of bothering with the autoresizingMask flag, I override layoutSubviews in custom UIView subclass:
- (void)loadView {
self.view = [ContentView view];
self.view.frame = CGRectMake(0, 0, 30, 100);
}
where ContentView is defined as:
#interface ContentView : UIView {
UIButton *button;
}
+ (id)view;
#end
#implementation ContentView {
+ (id)view {
return [[self new] autorelease];
}
- (id)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
button = [UIButton buttonWithType:UIButtonTypeCustom];
[self addSubview:button]; // Retains the button.
}
return self;
}
- (void)layoutSubviews {
const CGFloat margin = 5;
CGRect size = self.frame.size;
button.frame = CGRectMake(margin, margin,
size.width - 2 * margin,
size.height - 2 * margin);
}
}
Try this code.
- (void)loadView
{
CGRect screenBounds = [UIScreen mainScreen].bounds;
UIView *contentView = [[[UIView alloc] initWithFrame:screenBounds] autorelease];
self.view = contentView;
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = CGRectMake(5,5,screenBounds.size.width - 10,100);
[button setTitle:#"hello" forState:UIControlStateNormal];
button.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[contentView addSubview:button];
}

Problem with UIButton on subview of a cell

Okay, a short breif of my app before i explain the problem.
My app has two views for it's custom TableViewCell, one frontview, and one backview(which is revealed once you swipe your finger across the cell, much like the twitter-app).
Anywho, i wanted to have some buttons on the backview. I did this in the cellForRowAtIndexPath-method
The first you'll see here is how i assign labels to the cells. The secondary thing you'll see is the button. It's working fine.
UILabel *nextArtist = [UILabel alloc];
nextArtist.text = #"Rihanna";
nextArtist.tag = 4;
[cell setNextArtist:nextArtist];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(6 ,31, 110, 20);
[button setImage:[UIImage imageNamed:#"radionorge.png"] forState:UIControlStateNormal];
[button addTarget:self action:#selector(touched:) forControlEvents:UIControlEventTouchUpInside];
[cell.backView addSubview:button];
But, it's in the next method the problem occours.
-(void)touched:(id)sender {
// Here i want to get the UILabels for each cell. Such as nextArtist.
if ([sender isKindOfClass:[UIButton class]]) {
UIButton *button = (UIButton *)sender;
UIView *contentView = button.superview;
UIView *viewWithTag4 = [contentView viewWithTag:4];
if ([viewWithTag1 isKindOfClass:[UILabel class]]) {
UILabel *titleLabel = (UILabel *)viewWithTag4;
NSLog(#"Label: ",titleLabel.text);
}
}
}
So, i realised that i cannot just go to the superview of the button and find my labels there, because their in another subview. I have scanned all my views, but still cannot find the label.
I am very new at this, and the subclassing of the TableView-cell is something i implemented from someone who posted their code.
But, my assumption is that there are noe UILabels in my view, because i am not adding them as views, only drawing them, with the drawTextInRect-function.
[nextArtist drawTextInRect:CGRectMake(boundsX+200 ,46, 110, 15)];
I have tried to adding them as subviews, but with no luck. Could anyone help me?
// Some more code you may need to solve the puzzle(this is where the cell-views are made)
#implementation RadioTableCellView
- (void)drawRect:(CGRect)rect {
if (!self.hidden){
[(RadioTableCell *)[self superview] drawContentView:rect];
}
else
{
[super drawRect:rect];
}
}
#end
#implementation RadioTableCellBackView
- (void)drawRect:(CGRect)rect {
if (!self.hidden){
[(RadioTableCell *)[self superview] drawBackView:rect];
}
else
{
[super drawRect:rect];
}
}
#end
#interface RadioTableCell (Private)
- (CAAnimationGroup *)bounceAnimationWithHideDuration:(CGFloat)hideDuration initialXOrigin:(CGFloat)originalX;
#end
#implementation RadioTableCell
#synthesize contentView;
#synthesize backView;
#synthesize contentViewMoving;
#synthesize selected;
#synthesize shouldSupportSwiping;
#synthesize shouldBounce;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if ((self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])) {
[self setBackgroundColor:[UIColor clearColor]];
RadioTableCellView * aView = [[RadioTableCellView alloc] initWithFrame:CGRectZero];
[aView setClipsToBounds:YES];
[aView setOpaque:YES];
[aView setBackgroundColor:[UIColor clearColor]];
[self setContentView:aView];
[aView release];
RadioTableCellBackView * anotherView = [[RadioTableCellBackView alloc] initWithFrame:CGRectZero];
[anotherView setOpaque:YES];
[anotherView setClipsToBounds:YES];
[anotherView setHidden:YES];
[anotherView setBackgroundColor:[UIColor clearColor]];
[self setBackView:anotherView];
[anotherView release];
// Backview must be added first!
// DO NOT USE sendSubviewToBack:
[self addSubview:backView];
[self addSubview:contentView];
[self setContentViewMoving:NO];
[self setSelected:NO];
[self setShouldSupportSwiping:YES];
[self setShouldBounce:YES];
[self hideBackView];
}
return self;
}
Please help me, or at least point me in a direction or two!
//////////////////////////
Updated with some new code:
This is inside my RadioCustomCell, a UIView-subclass. It's here the UILabels are drawn
#import "RadioCustomCell.h"
#implementation RadioCustomCell
#synthesize nowTitle,nowArtist,nextTitle,nextArtist,ChannelImage;
// Setting the variables
- (void)setNowTitle:(UILabel *)aLabel {
if (aLabel != nowTitle){
[nowTitle release];
nowTitle = [aLabel retain];
[self setNeedsDisplay];
}
}
- (void)setNowArtist:(UILabel *)aLabel {
if (aLabel != nowArtist){
[nowArtist release];
nowArtist = [aLabel retain];
[self setNeedsDisplay];
}
}
- (void)setNextTitle:(UILabel *)aLabel {
if (aLabel != nextTitle){
[nextTitle release];
nextTitle = [aLabel retain];
[self setNeedsDisplay];
}
}
- (void)setNextArtist:(UILabel *)aLabel {
if (aLabel != nextArtist){
[nextArtist release];
nextArtist = [aLabel retain];
[self setNeedsDisplay];
}
}
- (void)setChannelImage:(UIImage *)aImage {
if (aImage != ChannelImage){
[ChannelImage release];
ChannelImage = [aImage retain];
[self setNeedsDisplay];
}
}
- (void)drawContentView:(CGRect)rect {
CGContextRef context = UIGraphicsGetCurrentContext();
//UIColor * backgroundColour = [UIColor whiteColor];
UIColor *backgroundColour = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:#"CellBackground.png"]];
[backgroundColour set];
CGContextFillRect(context, rect);
CGRect contentRect = self.contentView.bounds;
CGFloat boundsX = contentRect.origin.x;
[ChannelImage drawInRect:CGRectMake(boundsX+120 ,25, 75, 35)];
nowTitle.enabled = YES;
nowTitle.textAlignment = UITextAlignmentCenter;
nowTitle.font = [UIFont fontWithName:#"HelveticaNeue-Bold" size: 14.0];
nowTitle.textColor = [UIColor blackColor];
nowTitle.backgroundColor = [UIColor clearColor];
//[nowTitle drawTextInRect:CGRectMake(boundsX+6 ,31, 110, 20)];
// Trying to add a subview instead of drawing the text
nowTitle.frame = CGRectMake(boundsX+6 ,31, 110, 20);
[self addSubview:nowTitle];
// I have also tried adding it to super, no effect.
nowArtist.enabled = YES;
nowArtist.textAlignment = UITextAlignmentCenter;
nowArtist.font = [UIFont fontWithName:#"HelveticaNeue" size: 10.0];
nowArtist.textColor = [UIColor blackColor];
nowArtist.backgroundColor = [UIColor clearColor];
[nowArtist drawTextInRect:CGRectMake(boundsX+6 ,46, 110, 15)];
nextTitle.enabled = NO;
nextTitle.textAlignment = UITextAlignmentCenter;
nextTitle.font = [UIFont fontWithName:#"HelveticaNeue-Bold" size: 12.0];
[nextTitle drawTextInRect:CGRectMake(boundsX+200 ,31, 110, 20)];
nextArtist.enabled = NO;
nextArtist.textAlignment = UITextAlignmentCenter;
nextArtist.font = [UIFont fontWithName:#"HelveticaNeue" size: 9.0];
[nextArtist drawTextInRect:CGRectMake(boundsX+200 ,46, 110, 15)];
}
You just forgot to init your UILabel in your very first line of code. :)
At the first look, I can be sure that if you draw the text (and the text is not the label), then there is no UILabel at all in your cell. You can ignore that way.
So, if you don't have the UILabel, how you can get the text. Because your contentView is indeed a RadioTableCellView, then it is not hard. In your class, just public a property called nextArtist. When your button is tapped, look up for the contentView (by calling some superview), cast it to RadioTableCellView then get the nextArtist out
Without writing a bunch of code, here's my best guess.
You're going to need to assign tags to aView and anotherView in your initWithStyle: method. I'm going to assume you have a couple constants: BACK_VIEW_TAG and FRONT_VIEW_TAG.
In your touched: method, walk up the view hierarchy until you find your UITableViewCell.
UIView *currentView = button.superView;
while (![currentView isKindOfClass:UITableViewCell] && currentView != nil) {
currentView = currentView.parent;
}
Get the front view and back view (or which ever you want) from the table cell's contentView using the tags.
if (currentView != nil) {
UITableViewCell *cellView = (UITableViewCell *)currentView)
UIView *cellContentView = cellView.contentView;
UIView *backView = [cellContentView viewWithTag:BACK_VIEW_TAG];
UIView *frontView = [cellContentView viewWithTag:FRONT_VIEW_TAG];
// Get other views from frontView and backView using viewWithTag:.
}
Note that you should be adding views to your UITableViewCell subclass's contentView, not to the UITableViewCell directly. See Programmatically Adding Subviews to a Cell’s Content View for details.