2009-03-19 3 views
5

내 아이폰 애플리케이션에 액션 시트 팝업이 있습니다. 미리 결정한 값 대신 배열에서 문자열로 채우고 싶습니다.배열로 액션 시트 채우기

온라인으로이 작업을 수행 할 수 없습니다. 아마도 작업 표를 사용하는 것이 옳지 않은가?

roomspopup = [ [ UIActionSheet alloc ] 
        initWithTitle: alertname 
        delegate: self 
        cancelButtonTitle: @"Cancel" 
        destructiveButtonTitle: nil 
        otherButtonTitles: @"Kitchen", "Dining Room", nil ]; 

을하지만, 대신에 "부엌"과 "식당은"나는 그것이 배열에서 기입 싶습니다

는 지금이 내가 그것을 구축하기 위해 사용하고 있습니다 것입니다. 배열의 크기 (즉, 객실 수)는 고정 된 숫자가 아닙니다.

답변

7

한 줄로 입력 할 수 없습니다. 빈 세트로 initWithTitle을 호출 한 다음 addButtonWithTitle:을 사용하여 루프가있는 다른 버튼을 추가해야합니다.

14

취소 버튼없이 UIActionSheet를 초기화하기 당신이 당신의 다른 버튼을 추가 한 후이 취소 버튼을 추가하는 것입니다 그것을 해결하는 방법을 @JimTrell. 전무의의 무리와 함께 시트 초기화 먼저

:

UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Choose" 
         delegate:self 
         cancelButtonTitle:nil 
         destructiveButtonTitle:nil 
         otherButtonTitles:nil]; 

그리고 마지막으로 addButtonWithTitle: 및 사용하여 배열을 통해 루프가 추가 버튼을 취소하고 색인 설정 :

[actionSheet addButtonWithTitle:@"Cancel"]; 
[actionSheet setCancelButtonIndex:[yourArray count]]; 
+1

더 일반적으로 : [actionSheet setCancelButtonInd 예 : [actionSheet numberOfButtons] - 1]; ' – Nestor

0

내가 설정할 수 있습니다 아래 코드를 사용하여 하단의 취소 버튼 :

anActionSheet = [[UIActionSheet alloc] initWithTitle:@"Change A/C" delegate:self 
    cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil, nil]; 

for (int i = 0; i < [arraylist count]; i++)  
    [anActionSheet addButtonWithTitle:[arraylist objectAtIndex:i]]; 

anActionSheet.cancelButtonIndex = [arraylist count];  
[anActionSheet addButtonWithTitle:@"Cancel"]; 
+0

anActionSheet.cancelButtonIndex = [arraylist count]; 요점은. U는 다른 모든 버튼 뒤에 취소 버튼이 설정되도록 반복 한 후에 hv를 선언합니다. –

관련 문제