먼저 다음 헤더 파일에서 :
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController <UIActionSheetDelegate>
- (IBAction)btnSheet1:(id)sender;
@property (weak, nonatomic) IBOutlet UILabel *myLabel;
-(void) actinSheet:(UIActionSheet *) actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex;
@end
그리고 구현 파일 :
#import "ViewController.h"
@implementation ViewController
- (IBAction)btnSheet1:(id)sender
{
UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"Action" delegate:self cancelButtonTitle:@"cancel" destructiveButtonTitle:@"Do it!" otherButtonTitles:@"other button", nil];
sheet.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
[sheet showInView:self.view];
}
-(void) actinSheet:(UIActionSheet *) actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
if(buttonIndex == 0)
{
self.myLabel.text = [NSString stringWithFormat:@"Button: %d pressed", buttonIndex];
}
else if (buttonIndex == 1)
{
self.myLabel.text = [NSString stringWithFormat:@"Button: %d pressed", buttonIndex];
}
}
@end
시뮬레이터를 실행했을 때 버튼과 라벨이 화면에 성공적으로 표시되었습니다. 그러나 버튼을 클릭하여 액션 시트가 팝업되도록 한 다음 myLabel
다른 문자열로 변경 하기 위해 버튼 중 하나를 누르려고 시도했을 때 레이블이 변경되지 않았습니다.
경고보기에서도 동일한 작업을 시도했지만 작동하지 않았습니다.
그렇다면 코드가 작동하지 않는 이유는 무엇입니까? 전체 스 니펫은 이 책의 내용 이며 그 책은 iOS 6 및 Xcode 4를 사용한다고 가정하지만 iOS 7 및 Xcode 5를 사용하는데 이것이 범인 일 수 있습니까?
참고로 라벨을에 연결하고 IBOutlet
버튼을에 연결했습니다 IBAction
.
감사.
작동하지 않습니다. 대리자를 잘못 작성하고 있습니다.
-(void) actinSheet:(UIActionSheet *) actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
이어야합니다 actionSheet
.
-(void) actionSheet:(UIActionSheet *) actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다