2013-07-10 5 views
0

프로토 타입 셀에서 IBOutlet을 지정할 수 없으므로 태그가있는 UIbutton에 핸들이 있습니다. 하지만 cellForRowAtIndexPath 버튼의 이미지를 설정할 때 활성화 및 비활성화 상태에 대한 올바른 이미지가 표시되지 않습니다. cellForRowIndexPath에서태그로 처리 할 때 UIButton 이미지가 올바르게 설정되지 않았습니다.

:

if([cellIdentifier isEqualToString:CELL_ID_COMPLIANCE]) 
    _infoButton = (UIButton *)[cell viewWithTag:800]; 
else 
    _infoButton = (UIButton *)[cell viewWithTag:900]; 

if([[comments objectAtIndex:kEntitlementComment] length] > 0){ 
    _infoButton.enabled= YES; 
    [_infoButton setImage:[UIImage imageNamed:@"icon_info.png"] forState:UIControlStateNormal]; 
    TRACELOG(@"the coments :%@", [comments objectAtIndex:kEntitlementComment]); 
    } 
else{ 
    _infoButton.enabled= NO; 
    [_infoButton setImage:[UIImage imageNamed:@"info_icon_disabled.png"] forState:UIControlStateDisabled]; 
    } 

나는 테이블의 프로토 타입 세포의 두 가지 종류가 있지만, 버튼 이미지는 이가지 있습니다. 나는 또한 선택에

Object:textArray waitUntilDone:YES]; 

내가 버튼의 이미지를 설정하고 함께

[self performSelectorOnMainThread:@selector(doButtonSettings:) 

을 시도했다. ButtonType은 개인 설정 도구이므로 동적으로 변경할 수 없습니다. 조건에 맞는 버튼 이미지를 만들려면 어떻게해야합니까?

+0

xib 또는 스토리 보드에서 버튼의 이미지를 직접 설정하지 않는 이유는 무엇입니까? 2 개의 프로토 타입 셀이 있다고 가정 해보십시오. – Adithya

+0

나는 당신이 틀린 tableviews 생각 ... –

+0

2 프로토 타입 세포가 다른 열을 가지고 서로 다른 권한을 가진 다른 사용자가 사용됩니다. 데이터가있는 경우에만 버튼이 활성화됩니다. 어쨌든 아래에 수정 사항을 게시했습니다. 고맙습니다. – ShaluRaj

답변

1

왜 버튼에 동일한 태그를 사용하지 않습니까?

//All prototype cells info buttons have the same tag 
_infoButton = (UIButton *)[cell viewWithTag:900]; 

if([[comments objectAtIndex:kEntitlementComment] length] > 0){ 
    _infoButton.enabled= YES; 
    [_infoButton setImage:[UIImage imageNamed:@"icon_info.png"] forState:UIControlStateNormal]; 
    TRACELOG(@"the coments :%@", [comments objectAtIndex:kEntitlementComment]); 
    } 
else{ 
    _infoButton.enabled= NO; 
    [_infoButton setImage:[UIImage imageNamed:@"info_icon_disabled.png"] forState:UIControlStateDisabled]; 
    } 
+0

나는 같은 태그를 사용하여 그것도 시도했다.. 그러나 아직도 행동은 무작위 다. .. – ShaluRaj

1

setImage에 대한 호출을 셀이 만들어진 위치로 이동하십시오. ALL 버튼에 대한 정상 및 비활성 상태에 대한 이미지를 설정하십시오. 귀하의 경우 문에서

당신은 단지 버튼 상태

if([[comments objectAtIndex:kEntitlementComment] length] > 0){ 
    _infoButton.enabled= YES; 
} 
else{ 
    _infoButton.enabled= NO; 
} 

를 전환해야하지만이 변화는 혼자 문제를 해결해서는 안된다. cellForRowIndexPath 내에 모든 코드를 게시하는 것이 도움이됩니다. 그 문제는 dequeueReusableCellWithIdentifier를 호출 한 곳보다 위에있는 것으로 의심되며 셀을 만들지 않는 경우.

0

나는 soln : 사실 IBAction 메서드에서 popover가 내 infoButton에 묶여있었습니다. - (IBAction를) infoButtonAction (ID) 송신기 이벤트 (ID) 이벤트 {

NSSet *touches = [event allTouches]; 
UITouch *touch = [touches anyObject]; 
CGPoint touchPoint = [touch locationInView:_summaryTableView]; 
NSIndexPath *indexPath = [_summaryTableView indexPathForRowAtPoint:touchPoint]; 
UITableViewCell *cell = [_summaryTableView cellForRowAtIndexPath:indexPath]; 

_infoButton.tag=indexPath.row; 

if ([self.myPopoverController isPopoverVisible]) 
{ 
    // Close the popover view if toolbar button was touched again and popover is already visible 
    [self.myPopoverController dismissPopoverAnimated: YES]; 
    return; 
} 

UIStoryboard      *storyboard  = [UIStoryboard storyboardWithName: @"iPad" bundle: nil]; 
NSITSLMEntitlementSummCommentsViewController *popoverContent = [storyboard instantiateViewControllerWithIdentifier: @"slm_ES_Comments"]; 

self.myPopoverController = [[UIPopoverController alloc] initWithContentViewController: popoverContent]; 
popoverContent.comments.text = [[self.dataController getSummaryRecordAtIndex:indexPath.row] objectAtIndex:kEntitlementComment]; 

// Present the popover view non-modally with a refrence to the toolbar button which was pressed 
if([popoverContent.comments.text length] > 0) 
    [self.myPopoverController presentPopoverFromRect:[sender frame] inView:cell permittedArrowDirections:UIPopoverArrowDirectionRight animated:YES]; 
_infoButton.tag= 800; 

}

INFO 버튼 태그 나 테이블의 버튼 중 하나를 누르면 때마다 변화시켰다. 그래서 마지막 줄을 추가하고 지금은 그 벌금을 추가했습니다. 고맙습니다. 어쨌든 ..

관련 문제