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 명의 아이폰 개발자들이 나보다 먼저하지 않은 것을 요구하지 않는다. 나는 생각하지 않는다. .
이 정보가 유용 할 수 있습니다. http://stackoverflow.com/questions/1802707/detecting-which-uibutton-was-pressed-in-a-uitableview – iwasrobbed