Why are my buttons not coming?

I configure two buttons inside UITableViewCells. The cell itself should not respond to the selection, only two buttons.

Here is the code in question:

-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *ident = @"ResourceResultsCells";

    ResourceResultsTableCell *cell = (ResourceResultsTableCell *)[tableView dequeueReusableCellWithIdentifier:ident];

    if (!cell) {
        NSArray *ary = [[NSBundle mainBundle] loadNibNamed:@"ResourceResultsTableCell" owner:nil options:nil];
        for (id thing in ary) {
            if ([thing isKindOfClass:[ResourceResultsTableCell class]]) {
                cell = (ResourceResultsTableCell *)thing;
            }
        }

    }

    NSDictionary *listing = [self.listings objectAtIndex:indexPath.row];

    cell.crewName.text = [listing objectForKey:@"ListingTitle"];
    cell.cityState.text = [NSString stringWithFormat:@"%@, %@",
                           [listing objectForKey:@"City"],
                           [listing objectForKey:@"State"]];
    cell.phone.text = [listing objectForKey:@"phone1"];
    cell.email.text = [self safeListingOf:@"Email" from:listing];

    UIImage *stretchy = [[UIImage imageNamed:@"grey_tab_stretchable.png"] stretchableImageWithLeftCapWidth:25 topCapHeight:0];
    [cell.callButton setBackgroundImage:stretchy forState:UIControlStateNormal];
    [cell.addToLightboxButton setBackgroundImage:stretchy forState:UIControlStateNormal];

    cell.callButton.tag = indexPath.row;
    cell.addToLightboxButton.tag = indexPath.row;

    //here where my trouble is....
    [cell.callButton addTarget:self action:@selector(call:) forControlEvents:UIControlEventTouchUpInside];
    [cell.addToLightboxButton addTarget:self action:@selector(addToLightbox:) forControlEvents:UIControlEventTouchUpInside];

    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;             
}

-(void)call:(id)sender
{
    UIButton *hit = (UIButton *)sender;
    NSLog(@"call with id %d", hit.tag);
}

-(void)addToLightbox:(id)sender
{
    UIButton *hit = (UIButton *)sender;
    NSLog(@"lightbox with id %d", hit.tag);
}

Literally everything about this works fine, except that pressing any of the buttons does not cause my NSLog to indicate that we have moved on to the methods that we are aiming at. No errors, just no messages.

My stretched images showing that my IB connections are ok in my user table cell.

It almost looks like a different top view, so they don’t get a click. But they are definitely the last ones added by my presentation. There is no question about this.

EDIT: HACKING CONTINUES !!

I just added the following code to my subclass of UITableViewCell:

-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{   
    if ([touches count] == 1) {
        for (UITouch *theTap in touches) {
            if (theTap.tapCount == 1) {
                CGPoint coords = [theTap locationInView:self.contentView];

                CGRect callButtonFrame = self.callButton.frame;
                if (coords.x > callButtonFrame.origin.x && coords.x < (callButtonFrame.origin.x + callButtonFrame.size.width) 
                    && coords.y > callButtonFrame.origin.y && coords.y < (callButtonFrame.origin.y + callButtonFrame.size.height)) {
                    [self call:callButton];
                }

                CGRect boxButtonFrame = self.addToLightboxButton.frame;

                if (coords.x > boxButtonFrame.origin.x &&  coords.x < (boxButtonFrame.origin.x + boxButtonFrame.size.width)
                    && coords.y > boxButtonFrame.origin.y && coords.y < (boxButtonFrame.origin.y + boxButtonFrame.size.height)) {
                    [self addToLightbox:addToLightboxButton];
                }
            }
        }
    }
}

, . , , . - , . . , , , ... , iPhone , .

+3
2

. , , , NSLog didselectrowatindexpath.

+1

, ( mac), bringSubviewToFront , , ?

0

Source: https://habr.com/ru/post/1754303/


All Articles