« お台場… | トップページ | 『甘味茶房 菊丸』で餡蜜♪ »

2009年10月 8日 (木)

『UIActionSheet』を使う時にチョットはまった…。

『iPhone』のプログラミングしていたら…
『UIActionSheet』の所でチョットはまった…。

最終的に分かった事は、プロジェクトを
『Windows-based Application』で作ったのが原因らしい…。

『View-based Application』で作った場合以下のプログラム動作する。

- (IBAction)pushDoButton:(id)sender {
    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"やるの?" delegate:self cancelButtonTitle:@"やめる" destructiveButtonTitle:@"やる" otherButtonTitles:nil];
    [actionSheet showInView:self.view];
    [actionSheet release];
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    if(buttonIndex!=0) {
        // 『やる』処理
    }
}

所が『Windows-based Application』だと、
まず『[actionSheet showInView:self.view];』が
エラーになる…。

最初、何でエラーが出るか分からなかったが…
色々なんかした結果『View-based Application』で
作られるビューだと気が付いた…。

で『[actionSheet showInView:self.window];』と
『window』にする事で解決したのだが…。

『delegate:self』の所で警告が出ていたので
『delegate:nil』にして警告を消していたら
『actionSheet』が呼び出されない…。

こんな警告…。
>warning: class 'xxxxApplicationDelegate' does not implement the 'UIActionSheetDelegate' protocol

『delegate:self』にすれば警告は出るが動く…。

どこかで設定し忘れているらしい…。

あ!ヘッダーを設定するのかぁ!?

とヘッダーを
>@interface xxxxAppDelegate : NSObject <UIApplicationDelegate> {
から
>@interface xxxxAppDelegate : NSObject <UIApplicationDelegate, UIActionSheetDelegate> {
に書き換えたら警告が出なくなった…。

最終的にこうなった。
xxxxAppDelegete.h
@interface xxxxAppDelegate : NSObject <UIApplicationDelegate, UIActionSheetDelegate> {
xxxxAppDelegete.m
- (IBAction)pushDoButton:(id)sender {
    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"やるの?" delegate:self cancelButtonTitle:@"やめる" destructiveButtonTitle:@"やる" otherButtonTitles:nil];
    [actionSheet showInView:self.view];
    [actionSheet release];
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    if(buttonIndex!=0) {
        // 『やる』処理
    }
}

柔軟なのは、良いけど…
分かり難いよ…。

初心者なんでRPG宜しく経験値を稼いでいる所…。(汗)

|

« お台場… | トップページ | 『甘味茶房 菊丸』で餡蜜♪ »

コメント

コメントどうも♪

役に立ったなら何より!!(^^)!

プログラム頑張ってください!

投稿: kouyou | 2013年6月 8日 (土) 22時16分

初心者です、参考になりました。どうもありがとうです。

投稿: | 2013年6月 8日 (土) 18時02分

コメントを書く



(ウェブ上には掲載しません)




トラックバック


この記事へのトラックバック一覧です: 『UIActionSheet』を使う時にチョットはまった…。:

« お台場… | トップページ | 『甘味茶房 菊丸』で餡蜜♪ »