インターフェイスビルダーを介して次のメソッドに接続されている 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でそのように設定しました)。ボタンを「有効」にする条件が満たされている場合、ボタンは正しく機能しません。はindex
0 に設定されますが、現在のページが正しく設定されず、カードは表示されません。奇妙なことに、ボタンを数回押すと、機能する可能性があります。
非常に断続的...
あなたが提供できる助けをありがとう