後,我有一種連接在UIBarButton,通過接口生成器,下面的方法:的UIBarButtonItem停止工作,我改變enabled屬性
- (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,但它不會正確設置當前頁面,並且卡片不會顯示。奇怪的是,按幾次按鈕後,它可能會工作。
非常間歇...
感謝您的幫助,您可以提供
我相信這行 - (void)btnJumpToStart_Touch:(id)發件人應改爲 - (IBAction)btnJumpToStart_Touch:(id)發件人。如果您在IB中設置了按鈕,那麼當您將新動作連接到按鈕時,您需要將方法設置爲IBActions。 – Popeye
@Popeye不,只要它在.h中聲明IBOutlet,就沒關係。 Void和IBOutlet是彼此的typedef。 – CodaFi
IBAction解析爲「無效」,IBOutlet解析爲無,但它們表示Xcode和Interface構建器可以在「接口」構建器中使用這些變量和方法來將UI元素鏈接到您的代碼。 如果你根本不打算使用Interface Builder,那麼你不需要它們在你的代碼中,但是如果你打算使用它,那麼你需要爲在IB中使用的方法指定IBAction, IB將用於IB中的對象。因此,如果您在Interface Builder中將此方法鏈接起來,則需要將該方法聲明爲IBAction。 – Popeye