我正在設計一個應用程序,要求我具有四種不同狀態的按鈕網格。 Unselected,Selected,Hit或Miss。我試圖以編程方式生成這些按鈕,但我遇到了麻煩,只保留其中一個按鈕。有沒有辦法,也許我可以把它們放入一個數組,然後迭代數組以取消選擇它們?我看着IBOutletCollections但這些不會起作用,因爲我要創建這些按鈕編程以編程方式鏈接的按鈕
0
A
回答
0
這爲我工作,其中_lastSelectedButton是最後的選擇按鈕的ID,寬度是25
-(void)unselect
{
if(_lastSelectedButton){
//Unselect the last selected button However only change its background if is blue
[[_lastSelectedButton layer] setBorderWidth:0.0f];
if([_lastSelectedButton.titleLabel.text isEqual: @"0"]){
[[_lastSelectedButton layer] setBackgroundColor:[missColor CGColor]];
}else if([_lastSelectedButton.titleLabel.text isEqual: @"/"]){
[[_lastSelectedButton layer] setBackgroundColor: [hitColor CGColor]];
}
else{
[[_lastSelectedButton layer] setBackgroundColor:unselectedColor.CGColor];
}
}
_lastSelectedButton = nil;
}
- (void)advanceSelection:(UIButton*)sender
{
int i = 0;
//Find the indice that the present selected thing is
for(UIButton *button in btnList)
{
if(sender == button)
{
if((i >= (self.numberOfPlayers - 1) * width) &&((i + 1) % 5 == 0)){
//Then animated scroll to the next frame
if (i + 1 == self.numberOfPlayers * width) {
//then it is the last button
[self unselect];
}else{
CGFloat x = (([_pageControl currentPage] + 1.0) * 320.0);
[_scrollView setContentOffset:CGPointMake(x, 0.0f) animated:YES];
[self selection:btnList[i - (width * (self.numberOfPlayers - 1)) + 1]];
[self scrollViewDidEndDecelerating:self.scrollView];
self.pageControl.currentPage = _pageControl.currentPage + 1;
}
}else if(i >= ((self.numberOfPlayers - 1) * width)){
//We want to move it up one
//subtract width times hieght and ad one
[self selection:btnList[i - (width * (self.numberOfPlayers - 1)) + 1]];
}else{
//To go one down add 25 (the width)
[self selection:btnList[i + 25]];
}
}
i++;
}
}
0
相關問題
- 1. 以編程方式向Outlook 2007添加超鏈接按鈕
- 2. 以編程方式按下按鈕
- 3. iPhone:以編程方式按下按鈕
- 4. 以編程方式按下此按鈕
- 5. 以編程方式編寫android:按鈕
- 6. Android以編程方式聲明按鈕?
- 7. 以編程方式點擊按鈕vb.net
- 8. 以編程方式點擊HTML按鈕
- 9. 以編程方式單擊MessageBox按鈕
- 10. 以編程方式點擊按鈕 - JS
- 11. 以編程方式居中按鈕
- 12. 以編程方式IBAction和按鈕
- 13. 以編程方式添加按鈕
- 14. 以編程方式禁用按鈕
- 15. 以編程方式切換按鈕on_state?
- 16. 以編程方式設置RoundedRect按鈕
- 17. 以編程方式創建的嚮導控制中禁用鏈接按鈕
- 18. 以編程方式鏈接CNContacts
- 19. 以編程方式點擊JQuery鏈接
- 20. 以編程方式觸發UIWebView中的鏈接長按
- 21. 執行Segue以編程方式沒有按鈕連接?
- 22. 以編程方式連接按鈕XCode9,Objective-C,OSX
- 23. 如何以編程方式生成按鈕名稱按鈕
- 24. 編程選擇超鏈接按鈕
- 25. 以編程方式設置按鈕對齊方式
- 26. 以編程方式設置等效於按鈕的按鍵
- 27. 以編程方式按下Sencha觸摸按鈕的Greasemonkey腳本
- 28. 設置WPF按鈕式編程方式
- 29. 以編程方式調用按鈕的點擊方法
- 30. 以編程方式更改按鈕的onClick方法?
聽起來像是你已經知道答案: 「把它們放到一個數組中,然後迭代數組以取消選擇它們」 - 這應該起作用 – dariaa
NSArray引用是「強壯的」。 –