Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 09-27-2010, 11:40 AM   #1 (permalink)
Registered Member
 
Join Date: Jul 2010
Posts: 8
Jensen2k is on a distinguished road
Default Problem with button-action in 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.
Code:
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.
Code:
-(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.

Code:
    [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)
Code:
@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!
Jensen2k is offline   Reply With Quote
Reply

Bookmarks

Tags
tableview, tableviewcell, uibutton

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 353
6 members and 347 guests
headkaze, mistergreen2011, nobstudio, Objective Zero, revg, v1n2e7t
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,655
Threads: 94,116
Posts: 402,889
Top Poster: BrianSlick (7,990)
Welcome to our newest member, pungs
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 11:08 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0