상황에 따라 달라지는 옵션이있는 작업 시트가 있습니다. 버튼 제목의 배열을 먼저 만들고 싶으면 다른 버튼 제목이 충분하지만,이를 varargs 형식으로 변환하는 방법을 알 수는 없습니다.UIActionSheet varargs init 메소드에 문자열 배열을 보내려면 어떻게해야합니까?
나는 이런 식으로 뭔가를 할 :
NSMutableArray *buttonTitles = [NSMutableArray array];
if (condition1) {
[buttonTitles addObject: @"Do action 1"];
}
if (condition2) {
[buttonTitles addObject: @"Do action 2"];
}
if (condition3) {
[buttonTitles addObject: @"Do action 3"];
}
if (condition4) {
[buttonTitles addObject: @"Do action 4"];
}
UIActionSheet *actionSheet = [[[UIActionSheet alloc] initWithTitle: nil delegate: self cancelButtonTitle: @"Cancel" destructiveButtonTitle: nil otherButtonTitles: buttonTitles] autorelease];
를 이제 분명히 내가 대신이 같은 뭔가를 할 수에 내가 가진 경우 :
UIActionSheet *actionSheet = nil;
if (condition1 && condition2 && condition3 && condition4) {
actionSheet = [[[UIActionSheet alloc] initWithTitle: nil delegate: self cancelButtonTitle: @"Cancel" destructiveButtonTitle: nil otherButtonTitles: @"Do action1", @"Do action2", @"Do action3", @"Do action 4", nil] autorelease];
} else if (condition1 && condition2 && condition3 && !condition4) {
actionSheet = [[[UIActionSheet alloc] initWithTitle: nil delegate: self cancelButtonTitle: @"Cancel" destructiveButtonTitle: nil otherButtonTitles: @"Do action1", @"Do action2", @"Do action3", nil] autorelease];
}
// else ...
// about 14 other cases!
을하지만 그건 끔찍한 일 것이다. 누구든지 나를 도울 수있는 훌륭한 통사론을 알고 있습니까?
는편집 : 내가 그것의 얼굴에 큰 보이는 addButtonWithTitle
를 사용하는 것이 제안되었다 는, 불행히도 이것은 바람직하지 않다 취소 버튼, 후 추가 버튼을 넣습니다. (가) 다른 모든 옵션 아래에서 취소 버튼을 선호
// adds a button with the title. returns the index (0 based) of where it was added. buttons are displayed in the order added except for the
// destructive and cancel button which will be positioned based on HI requirements. buttons cannot be customized.
HI 요구 사항 (애플의 휴먼 인터페이스 가이드 라인), 그래서 나는 애플을 말하고 싶지만 :
나는이 addButtonWithTitle
상태에서 자신의 문서부터 애플의 코드에 버그 믿는다 망했다. 물론, 그게 정말 도움이되지 않습니다. 그래서 NSArray와 varargs 사이를 변환하려고합니다. 아직 어떻게해야할지 모르겠군요.
for (Nstring *button in buttonTitles)
[actionSheet addButtonWithTitle:button];
나는이 방법이 효과가 있다고 생각했지만 편집과 관련하여 몇 가지 문제를 발견했습니다. –
수정을 확인하십시오. –
이것은 효과가 있습니다. 그래도 추가 타이틀을 망쳐 놓을 필요는없는 것처럼 보였다. –