1

私は1時間壁に頭をぶつけていました。このコードで作成されたボタンは起動するはずですが、起動しません。

-(void)createToolbar {

[self.bar removeFromSuperview];
self.bar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, screenWidth, TOOLBAR_HEIGHT)];
[self.bar setTintColor:self.userInfo.screenColorTrans];
[self.bar setTranslucent:YES];
NSMutableArray *buttons = [[NSMutableArray alloc] init];

    //It's the buttons send, trashButt, and editButt that appear and that change color when pressed (so I know they're registering user interaction) but that don't actually execute their methods.

UIBarButtonItem *send = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(share)];
[send setStyle : UIBarButtonItemStyleBordered];
UIBarButtonItem *flex = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:Nil];
if (self.ghhaiku.isUserHaiku) {
    UIBarButtonItem *trashButt = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemTrash target:self action:@selector(deleteHaiku)];
    [trashButt setStyle : UIBarButtonItemStyleBordered];
    UIBarButtonItem *editButt = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:@selector(editHaiku)];
    [trashButt setTintColor : self.userInfo.screenColorTrans];
    [editButt setTintColor : self.userInfo.screenColorTrans];
    [buttons addObject:editButt];
    [buttons addObject:trashButt];
}

            //Add the buttons to the nav bar.

[buttons addObject:flex];
[buttons addObject:send];
self.bar.items=buttons;
[self.view addSubview:self.bar];

            //Fade navigation bar: first delay, so that buttons are pressable, then fade.

double delayInSeconds = 3.5;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
    [UIView animateWithDuration:.5
                     animations:^{
                         self.bar.alpha = 0;
                     }];
});
}

セレクター メソッドのエラーではありません。これは、コードが「Yup」だけshareのメソッドに置き換えても、まだ実行されないためです。blahBlahNSLog

私が間違っていることについてのアイデアはありますか?

4

3 に答える 3

2

メソッド「createToolbar」またはviewdidloadのすぐ上にdeleteHaiku、share、editHaikuなどのメソッドを追加してみてください。上記のコードをcreateToolbarの代わりにviewdidloadに貼り付けてテストしました。それはまだ機能しません。

ここに画像の説明を入力

于 2013-02-05T03:01:07.760 に答える
0

アプリウィンドウがアプリデリゲートのように適切に設定されていることを確認してください:

 self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

このコードを試してください。

于 2013-07-22T05:04:47.763 に答える
0

送信者を引数として含めるようにアクション メソッドを変更してみてください。

- (void) share;

- (void) share:(UIBarButtonItem *)sender;

アクションを設定する場所も変更します。つまり、変更します

@selector(share)

@selector(share:)
于 2013-02-05T03:16:30.213 に答える