예, 내 github에서 OHActionSheet
을 참조하십시오.
블록을 사용하여 구현되므로 소스 코드의 대상/작업 코드를 추방하지 않고도이 방법으로 사용할 수 있습니다. 모든 것이 소스 코드의 동일한 위치에 있으며, 당신은 동일한 컨트롤러에서 원하는대로 당신은 많은 OHActionSheets
를 사용할 수있는
NSURL* anURL = ... // some URL (this is only as an example on using out-of-scope variables in blocks)
[OHActionSheet showSheetInView:yourView
title:@"Open this URL?"
cancelButtonTitle:@"Cancel"
destructiveButtonTitle:nil
otherButtonTitles:[NSArray arrayWithObjects:@"Open",@"Bookmark",nil]
completion:^(OHActionSheet* sheet,NSInteger buttonIndex) {
if (buttonIndex == sheet.cancelButtonIndex) {
NSLog(@"You cancelled");
} else {
NSLog(@"You choosed button %d",buttonIndex);
switch (buttonIndex-sheet.firstOtherButtonIndex) {
case 0: // Open
// here you can access the anURL variable even if this code is executed asynchrously, thanks to the magic of blocks!
[[UIApplication sharedApplication] openURL:anURL];
break;
case 1: // Bookmark
default:
// Here you can even embed another OHAlertView for example
[OHAlertView showAlertWithTitle:@"Wooops"
message:@"This feature is not available yet, sorry!"
cancelButton:@"Damn"
otherButtons:nil
onButtonTapped:nil]; // no need for a completion block here
break;
} // switch
}
}];
[편집] 자세한 내용과 예문을 추가 할 수있는 편집 샘플 코드를
이 좋아 보인다,하지만 여전히 정의해야 버튼 제목의 배열, 인덱스를 기반으로 한 것들을 얻은 다음, 그것을 selec으로 바꿉니다. tors, 당신이 그 행동을 전달하고 싶다면. 나는 'UIButton'과 같은 것을 원했다. 제목, 셀렉터, 타겟을 한 번에 정의하면된다. – zekel
블록 접근법에 대해 좋아하는 한 가지 점은 첫 번째 표시 할 때 알 수 있으므로 동일한 UIBarButtonItem을 통해 후속 작업 시트를 쉽게 표시 할 수 있다는 것입니다. (정상적인 UIActionSheet로 이것을 수행하는 좋은 방법을 모르겠습니다.) – zekel
(내가 액션을 전달하고자하는 이유는 모두 응답하는 여러보기 컨트롤러에서 사용하는 작업 시트를 갖는 것입니다.) – zekel