0

インターフェイスビルダーを介して次のメソッドに接続されている UIBarButton があります。

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

index実装の早い段階で定義されます。 setCurrentPageこれは:

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

}

最後に、showCardこれは次のとおりです。

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

ご覧のbtnJumpToStartとおり、メソッドで が無効または有効になりsetCurrentPageます。無効として開始されます(IBでそのように設定しました)。ボタンを「有効」にする条件が満たされている場合、ボタンは正しく機能しません。はindex0 に設定されますが、現在のページが正しく設定されず、カードは表示されません。奇妙なことに、ボタンを数回押すと、機能する可能性があります。

非常に断続的...

あなたが提供できる助けをありがとう

4

2 に答える 2

0

わかりましたので、コントロールを有効/無効にするコードをコメントアウトしました。次に、IBでボタンが有効になるようにしました。

シミュレーターで製品をいじってみました。それが終わったら、そのコードのコメントを外し、最初にボタンを無効に戻しました。今それは動作します...

于 2012-07-01T23:01:57.267 に答える
0

@Popeyeが言及したようににを設定してみ-(void)btnJumpToStart_Touch:(id)senderてください。-(IBAction)btnJumpToStart_Touch:(id)senderそれでもうまくいかない場合はUIBarButton、コントローラーのviewDidLoad.

于 2012-07-01T21:54:27.433 に答える