Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

keolsen

macrumors newbie
Original poster
May 19, 2008
1
0
Hi

As the title says, I have a problem implementing a button in an accessory view.
Let me explain...
I have a custom tableview controller and when the cells are being populated with content, the accessoryview is additionally set up containing a UIButton that calls a local function upon UIControlEventTouchUpInside.

It nearly works...but the button in the accessoryview only calls the action when I touch the left half of the button???

Some of my code is below...is it sufficient ?

Code:
- (UITableViewCell *)tableView: (UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        Class listClass = NSClassFromString(self.listItemClass);
        cell = [[[listClass alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
        cell.textLabel.font = kItemFont;
        cell.textLabel.adjustsFontSizeToFitWidth = kItemFontShrink;
        cell.detailTextLabel.font = kItemSubtitleFont;
    }
    
    if (self.listItems != nil && self.listItems.count > indexPath.row) {
        NSDictionary *listItem = [self.listItems objectAtIndex:indexPath.row];
        
        cell.imageView.image = [UIImage imageNamed:[listItem objectForKey:kKeyItemIcon]];
        
        cell.textLabel.text = [[listItem objectForKey:kKeyItemText] uppercaseString];
        cell.detailTextLabel.text = [[listItem objectForKey:kKeyItemSubtitleText] uppercaseString];
        
        NSString *textColorString = [listItem objectForKey:kKeyItemTextColor];
        NSString *subtitleColorString = [listItem objectForKey:kKeyItemSubtitleTextColor];
        
        cell.textLabel.textColor = (textColorString != nil) ? [self _colorFromString:textColorString] : kItemFontColor;  
        cell.detailTextLabel.textColor = (subtitleColorString != nil) ? [self _colorFromString:subtitleColorString] : kItemSubtitleFontColor;
        
        NSDictionary *accessoryObject = [listItem objectForKey:kKeyItemAccessoryObject];
        if (accessoryObject != nil) {
            UIButton *accessoryButton = [UIButton buttonWithType:UIButtonTypeCustom];
            accessoryButton.frame = CGRectMake(0, 0, 200, 100);
            [accessoryButton setImage:[UIImage imageNamed:[accessoryObject objectForKey:kKeyAccessoryIcon]] forState:UIControlStateNormal];
            [accessoryButton setBackgroundColor:[UIColor blueColor]];
            [accessoryButton addTarget:self action:@selector(_didTapAccessoryButton: ) forControlEvents:UIControlEventTouchUpInside];
            [cell setAccessoryView:accessoryButton];
            
        } else {
            cell.accessoryView = nil;
        }
    } else {
        cell.imageView.image = [UIImage imageNamed:@"orange_cirkel"];
        cell.textLabel.text = @"LIST ITEM";
        cell.detailTextLabel.text = @"ADDITIONAL TEXT";
    }
    
    return cell;
}
 
Last edited by a moderator:

jnoxx

macrumors 65816
Dec 29, 2010
1,343
0
Aartselaar // Antwerp // Belgium
You type some weird code :p but anyhow, I think you're having an label over button issue, try changing the background of your labels and stuff, to see if it's coming over the button :)

Ciao.
 
Last edited by a moderator:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.