2014-12-31 2 views
1

내 iOS 8 애플리케이션에서 UIActionSheet를 사용하고 있습니다. willPresentActionSheet 대리자 메서드에서 단추 제목의 색을 변경하려고했지만 해당 하위보기로 단추를 인식하지 못합니다. UIActionSheetdelegate가 하위 뷰를 가져 오지 못합니다.

나는이 같은 UIActionSheet 건설 :

UIActionSheet *popup = [[UIActionSheet alloc] initWithTitle:@"Select an Option" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles: nil]; 
popup.tag = 2; 
[popup addButtonWithTitle:@"Add Tag To Chat"]; 
[popup addButtonWithTitle:@"Remove Tag From Chat"]; 
[popup addButtonWithTitle:@"Terminate"]; 
[popup addButtonWithTitle:@"Cancel"]; 
[popup showInView:self.view]; 

위임은 다음과 같습니다

- (void)willPresentActionSheet:(UIActionSheet *)actionSheet 
{ 
    NSLog(@"%d",[actionSheet.subviews count]); 
    for (UIView *subview in actionSheet.subviews) { 
     if ([subview isKindOfClass:[UIButton class]]) { 
      UIButton *button = (UIButton *)subview; 
      [button setTitleColor:[UIColor redColor] forState:UIControlStateNormal]; 
     } 
    } 
} 

버튼 보이고있다, 나는 클릭하고 조치를 수행합니다. 하지만 count = 0이라고합니다. 왜?

+0

액션 시트는 iOS 7에서와 같이 사용자 정의 할 수 없습니다. 다른 OS 버전에서 단순히 충돌을 일으킬 수있는 방식을 해킹하려고하기 때문에 모든 오픈 소스를 대체하십시오. – Shubhank

+1

iOS 8에서,'UIActionSheet'는 새로운'UIAlertController'로 구현됩니다. 이것은 완전히 다른데 어떤 방식 으로든 사용자 정의 할 수 없습니다. 원하는 것을 지원하는 사용자 정의 구현을 작성하거나 사용해야합니다. – rmaddy

+0

[이것은 가장 좋은 (그리고 사용자 정의 할 수있는) 오픈 소스 작업 시트 중 하나입니다] (https://github.com/fastred/AHKActionSheet) – MendyK

답변

-2

하위 뷰 수를 확인하려는 대리인 방법 : willPresentActionSheet이 부적절한 것 같습니다.

willPresentActionSheet 실제로 액션 시트가 렌더링되기 전에 호출됩니다.

didlPresentActionSheet에서 하위보기의 수를 확인하면 더 적절할 것입니다. 이 도움이

희망 ..

+0

아니, 그건 작동하지 않습니다. – Rashad

+0

iOS 8을 확인할 수 있습니다. –

+0

네, 왜 안됩니까? – Rashad

1

는 파단의 UIColor 변경이 방법을 시도해보십시오

UIActionSheet * action = [[UIActionSheet alloc] 
           initWithTitle:@"Title" 
           delegate:self 
           cancelButtonTitle:@"Cancel" 
           destructiveButtonTitle:nil 
           otherButtonTitles:@"",nil]; 
[[[action valueForKey:@"_buttons"] objectAtIndex:0] setTitleColor:[UIColor redColor] forState:UIControlStateNormal]; 

나는 그것을 시도했습니다. 그것은 작동 중입니다 ...