2013-05-26 3 views
0

"내 앱에 요금 적용"팝업을 추가하고 싶습니다. 현재 UIAlertView를 통해이를보고 있습니다.등급 팝업을위한 버튼이 추가 된 uialertview

제목과 취소/완료 버튼으로 알림이 잘 보입니다.

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Rate this App" 
               message:@"My message" delegate:self 
             cancelButtonTitle:@"Cancel" 
             otherButtonTitles:@"OK", nil]; 
[alert show]; 

"내 메시지"섹션을 5 개의 사용자 지정 단추 (별표)로 바꾸십시오.

uialertview의 중간 부분에 사용자 정의 버튼 행을 어떻게 추가 할 수 있습니까?!

답변

1

당신은 [alertView addSubview:[[UIButton alloc] init:...]]

  • 이 UIAlertView에서 새 뷰를 상속 두 가지 옵션

    1. 사용을하고 단 하나 개의 자리에 표시되면 내부적

    수행 1입니다 빠르고 쉬운 솔루션입니다. 각 버튼마다 태그를 설정하고 동일한 클릭 이벤트를 추가 할 수 있습니다.

    // Interface.h 
    
    NSArray *allButtons; 
    
    // Implementation.m 
    
    UIAlertView *alert = [[UIAlertView alloc] init:...]; 
    
    UIButton *one = [UIButton buttonWithType:UIButtonTypeCustom]; 
    UIButton *two = [UIButton buttonWithType:UIButtonTypeCustom]; 
    ... 
    
    // Load "empty star" and "filled star" images 
    UIImage *starUnselected = ...; 
    UIImage *starSelected = ...; 
    
    [one setImage:starUnselected forControlState:UIControlStateNormal]; 
    [one setImage:starSelected forControlState:UIControlStateSelected]; 
    // repeat for all buttons 
    ... 
    
    [one setTag:1]; 
    [two setTag:2]; 
    ... 
    
    [one addTarget:self action:@selector(buttonPressed:) 
        forControlEvents:UIControlEventTouchUpInside]; 
    
    // repeat for all buttons 
    
    allButtons = [NSArray arrayWithObjects:one, two, three, four, five]; 
    
    // all buttons should subscribe 
    - (void)buttonPressed:(UIButton)sender 
    { 
        int tag = [sender getTag]; // The rating value 
    
        for (int i = 0; i < [allButtons length]; i++) 
        { 
         BOOL isSelected = i < tag; 
    
         [(UIButton)[allButtons objectAtIndex:i] setSelected:isSelected]; 
        } 
    
        // Set alertTag to store current set one 
        // read [alert getTag] when OK button is pressed 
        [alert setTag:tag]; 
    } 
    
  • +0

    한 지점에서만 사용되며 옵션 1은 올바르게 들립니다. 답변 포인트 1에서 코드 스 니펫을 확장 할 수 있습니까? UIAlertView에 단추를 추가하려고했지만 오류가 발생했습니다. – Richard

    +0

    예제를 확장했습니다. 오류는 무엇입니까? –

    +0

    나는이 모든 것이 현명하게 작동한다. 귀하의 본보기와 의견은 큰 도움이되었으며 많은 감사를드립니다! 많은 감사합니다! – Richard