2010-07-12 5 views
3

UITableViewCells 안에 두 개의 버튼을 설정하고 있습니다. 셀 자체가 선택에 응답해서는 안되며, 단지 두 개의 버튼만으로는 안됩니다.내 버튼이 왜 보이지 않습니까?

여기에 문제의 코드입니다 :이 약

-(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's 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); 
} 

말 그대로 모든 것을 제외하고, 좋은 작품 두 버튼 중 하나는 우리가 우리가 목표로하고있는 방법에 왔 나타내는 내 NSLog 발생하지 않습니다 도청. 오류가 없으며 메시지가 없습니다.

내 신축성있는 이미지가 나타나면 내 맞춤 테이블 셀의 펜촉에 내 IB 연결 상태가 양호하다고 알립니다.

다른보기가 맨 위에 올라가서 클릭을받지 못하는 것과 같습니다. 하지만 분명히 내 xib에 의해 마지막으로 추가 된 것들입니다. 그것에 대해 질문 없습니다.

편집 : 해킹 계속!

난 그냥 내있는 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]; 
       } 
      } 
     } 
    } 
} 

을 유쾌하게 충분이 작동합니다. 그러나 이와 같은 단추 접촉 감지 코드를 다시 구현해야한다는 것은 기괴합니다. 내 버튼이 꼭지를받지 못하는 이유는 아직 모르겠습니다. 나는이 솔루션에 크게 만족하지 않는다. 진짜 문제가 발견되지 않는다면 그걸로 제작에 들어갈 수있을 것 같아요.하지만 ... 나는 100 명의 아이폰 개발자들이 나보다 먼저하지 않은 것을 요구하지 않는다. 나는 생각하지 않는다. .

+0

이 정보가 유용 할 수 있습니다. http://stackoverflow.com/questions/1802707/detecting-which-uibutton-was-pressed-in-a-uitableview – iwasrobbed

답변

0

이것이 큰 도움이되는지는 모르겠지만 (각자의 맥이 아니다) 각 버튼에 bringSubviewToFront 전화를 걸어 시청 계층 구조 앞에 있는지 확인할 수 있습니까?

+0

도움이 필요하지 않습니다. 나는 그들이 이미 앞에 있다는 것을 확신했다. 자, 나는 셀에서 그것을 호출했다 .contentView, 내 버튼의 부모보기이다. 더 상위 계층 구조에서 호출해야한다고 생각하십니까? –

+0

나는'[MyCell.view bringSubviewToFront : button1];을 시도 할 것이다. –

+0

@ 제시 : 그것을 시도했다. 나는 "구조 또는 조합이 아닌 무언가에 구성원보기 요청"을 받는다. UITableViewCell은'.view'가 아닌'.contentView'라는 메인 뷰 속성의 이름을 지정합니다. 일관성이없는 것 같지만 UIView 하위 클래스이고 UIViewController 하위 클래스가 아니기 때문에 그럴 것 같습니다. –

1

흥미로운 문제. 셀이 캡쳐하고 있는지 확인하기 만하면 doselectrowatindexpath 메소드에 NSLog를 추가합니다.

+0

그래, 그 반응한다. 버튼을 클릭하면 포함됩니다. (나는 지금 Simulator에 있는데, 클릭 할 때 정확할 수 있습니다.) 나는 그들이 클릭을 포착하고 셀에 전달하지 않을 것이라고 생각했습니다. –

+0

You 've nudged 나 아래로. .. 잘 아마 오른쪽 트랙이 아니라, 선로. OP 질문에 대한 편집을 참조하십시오. –

관련 문제