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;
                     }];
});
}

这不是选择器方法中的错误——我知道这一点,因为如果我用唯一代码为“是”share的方法替换,它仍然不会这样做。blahBlahNSLog

关于我做错了什么的任何想法?

4

3 回答 3

2

尝试在方法“createToolbar”或 viewdidload 上方添加您的方法,如 deleteHaiku、share、editHaiku。我刚刚测试了它,通过将上面的代码粘贴到我的 viewdidload 而不是 createToolbar。它有效。这是截图。让我知道是否它仍然不起作用。

在此处输入图像描述

于 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 回答