0

I have a UIBarButton that is connected, through the interface builder, to the following method:

- (void)btnJumpToStart_Touch:(id)sender {
     index = 0;
     [self setCurrentPage];
     [self showCard];
}

index is defined early in the implementation. setCurrentPage is this:

- (void)setCurrentPage {

    // I need to set the bottom page control first,
    // this allows me to display that the user is viewing the 
    // first half of the deck or the second
    if(index < 11) {
        [self.bottomPageControl setCurrentPage:0];
    }
    else {
        [self.bottomPageControl setCurrentPage:1];
    }

    // now we set the top page control.  I use the index that is being displayed,
    // then divided by whether or not the bottom page control is showing the 
    // first half, or the second
    [self.topPageControl setCurrentPage:(index - ((deck.count / 2) * self.bottomPageControl.currentPage))];

    // next I set the 'jump to end/jump to start' button's enabled properties

    // the jump to end will only be anabled when the 
    // index is less than the deck's count - 1
    if(index < ([deck count] - 1)) {
        [self.btnJumpToEnd setEnabled:YES];
    }
    else {
        [self.btnJumpToEnd setEnabled:NO];
    }

    // the jump to start will only be enabled when the
    // index is greater than 0
    if(index > 0) {
        [[self btnJumpToStart] setEnabled:YES];
    }
    else {
        [[self btnJumpToStart] setEnabled:NO];
    }

}

Finally, showCard is this:

- (void)showCard {
    Card *card = [deck cardAtIndex:index];
    [cardImage setImage:[UIImage imageNamed:card.imageFile]];
}

Now, as you can see, the btnJumpToStart will be disabled, or enabled, in the setCurrentPage method. it will start out as disabled (I set it as such in the IB). When the criteria is met to 'enable' the button, it doesn't work properly. The index will be set to 0, but it won't set the current page properly, and the card is not shown. The weird thing is that after a few presses of the button, it might work.

Very intermittent...

Thanks for any help you can provide

4

2 回答 2

0

尝试将其设置-(void)btnJumpToStart_Touch:(id)sender-(IBAction)btnJumpToStart_Touch:(id)sender@Popeye 提到的。如果这不起作用,请尝试UIBarButton在控制器的viewDidLoad.

于 2012-07-01T21:54:27.433 回答
0

好的,所以我注释掉了启用/禁用控件的代码。然后我做到了,以便在 IB 中启用按钮。

我在模拟器中玩过这个产品。完成此操作后,我取消了该代码的注释,然后将按钮重新设置为在开始时禁用。现在它工作...

于 2012-07-01T23:01:57.267 回答