Only left half of accessory button responds to touchupinside

Discussion in 'iOS Programming' started by keolsen, May 21, 2012.

  1. keolsen, May 21, 2012
    Last edited by a moderator: May 21, 2012

    macrumors newbie

    Joined:
    May 19, 2008
    #1
    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;
    }
     
  2. jnoxx, May 21, 2012
    Last edited by a moderator: May 21, 2012

    macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #2
    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.
     

Share This Page