これが起こっていることです。私が持っている5つのセグメントのうち、セグメント「0」(iosのセグメントコントロールは右に0をカウントするため、最も右)をクリックすると、最初に「0」である正しいセグメントを通過します。しかし、2回目にクリックすると、セグメント3をクリックしたと思われますか?! これは非常に奇妙です!誰かが私を助けることができますか?これが私のコードです:
if ([[_segmentControlTableFunctions.subviews objectAtIndex:2]isSelected] )
{
[[_segmentControlTableFunctions.subviews objectAtIndex:2] setTintColor:newSelectedTintColor];
[[_segmentControlTableFunctions.subviews objectAtIndex:1] setTintColor:originalColor];
[[_segmentControlTableFunctions.subviews objectAtIndex:3] setTintColor:originalColor];
[[_segmentControlTableFunctions.subviews objectAtIndex:4] setTintColor:originalColor];
[self removeAllTables];
[self displayTables:[Globals sharedInstance].StartUp.Tables];
self.tableManagement.scrollEnabled = YES;
}else if ([[_segmentControlTableFunctions.subviews objectAtIndex:3]isSelected] ){
[[_segmentControlTableFunctions.subviews objectAtIndex:3] setTintColor:newSelectedTintColor];
[[_segmentControlTableFunctions.subviews objectAtIndex:1] setTintColor:originalColor];
[[_segmentControlTableFunctions.subviews objectAtIndex:2] setTintColor:originalColor];
[[_segmentControlTableFunctions.subviews objectAtIndex:4] setTintColor:originalColor];
[self removeAllTables];
[self displayTables:[Globals sharedInstance].StartUp.Tables];
}else if ([[_segmentControlTableFunctions.subviews objectAtIndex:4]isSelected] ){
[[_segmentControlTableFunctions.subviews objectAtIndex:4] setTintColor:newSelectedTintColor];
[[_segmentControlTableFunctions.subviews objectAtIndex:1] setTintColor:originalColor];
[[_segmentControlTableFunctions.subviews objectAtIndex:2] setTintColor:originalColor];
[[_segmentControlTableFunctions.subviews objectAtIndex:3] setTintColor:originalColor];
[self removeAllTables];
[self displayTables:[Globals sharedInstance].StartUp.Tables];
self.tableManagement.scrollEnabled = YES;
}else if ([[_segmentControlTableFunctions.subviews objectAtIndex:1]isSelected] ){
self.currentTable = @"-1";
_firstTableForCombine = @"-1";
_nextTable = @"-1";
_splitTable = @"-1";
_lastsegmentIndex = -1;
_segmentOneClicked = false;
_segmentTwoClicked = false;
_segmentZeroClicked = false;
[self.SplitForm removeFromSuperview];
[self.roundFrameForSplit removeFromSuperview];
[self.moveOrderToA removeFromSuperview];
[self.moveOrderToB removeFromSuperview];
[[_segmentControlTableFunctions.subviews objectAtIndex:4] setTintColor:originalColor];
[[_segmentControlTableFunctions.subviews objectAtIndex:1] setTintColor:newSelectedTintColor];
[[_segmentControlTableFunctions.subviews objectAtIndex:2] setTintColor:originalColor];
[[_segmentControlTableFunctions.subviews objectAtIndex:3] setTintColor:originalColor];
wait((int*)1000);
[self removeAllTables];
[self displayTables:[Globals sharedInstance].StartUp.Tables];
_segmentControlTableFunctions.selectedSegmentIndex = UISegmentedControlNoSegment;
[NSTimer scheduledTimerWithTimeInterval: 0.2
target: self
selector: @selector (changeToOriginalColor)
userInfo: nil
repeats: NO];
self.tableManagement.scrollEnabled = YES;
}else if ([[_segmentControlTableFunctions.subviews objectAtIndex:0]isSelected] ){
[[_segmentControlTableFunctions.subviews objectAtIndex:0] setTintColor:originalColor];
if(_segmentControlTableFunctions.selectedSegmentIndex == 0 && _segmentZeroClicked)
{
[self Normal];
}else
{
[self magnify];
}
}
編集されたコード:
//This handles all the background color of the segment control when the user clicks on
//one of the functions.
if (_segmentControlTableFunctions.selectedSegmentIndex == 2 )
{
[[_segmentControlTableFunctions.subviews objectAtIndex:2] setTintColor:newSelectedTintColor];
[[_segmentControlTableFunctions.subviews objectAtIndex:1] setTintColor:originalColor];
[[_segmentControlTableFunctions.subviews objectAtIndex:3] setTintColor:originalColor];
[[_segmentControlTableFunctions.subviews objectAtIndex:4] setTintColor:originalColor];
[self removeAllTables];
[self displayTables:[Globals sharedInstance].StartUp.Tables];
self.tableManagement.scrollEnabled = YES;
}else if (_segmentControlTableFunctions.selectedSegmentIndex == 1 ){
[[_segmentControlTableFunctions.subviews objectAtIndex:3] setTintColor:newSelectedTintColor];
[[_segmentControlTableFunctions.subviews objectAtIndex:1] setTintColor:originalColor];
[[_segmentControlTableFunctions.subviews objectAtIndex:2] setTintColor:originalColor];
[[_segmentControlTableFunctions.subviews objectAtIndex:4] setTintColor:originalColor];
[self removeAllTables];
[self displayTables:[Globals sharedInstance].StartUp.Tables];
}else if (_segmentControlTableFunctions.selectedSegmentIndex == 0 ){
[[_segmentControlTableFunctions.subviews objectAtIndex:4] setTintColor:newSelectedTintColor];
[[_segmentControlTableFunctions.subviews objectAtIndex:1] setTintColor:originalColor];
[[_segmentControlTableFunctions.subviews objectAtIndex:2] setTintColor:originalColor];
[[_segmentControlTableFunctions.subviews objectAtIndex:3] setTintColor:originalColor];
[self removeAllTables];
[self displayTables:[Globals sharedInstance].StartUp.Tables];
self.tableManagement.scrollEnabled = YES;
}else if (_segmentControlTableFunctions.selectedSegmentIndex == 3){
self.currentTable = @"-1";
_firstTableForCombine = @"-1";
_nextTable = @"-1";
_splitTable = @"-1";
_lastsegmentIndex = -1;
_segmentOneClicked = false;
_segmentTwoClicked = false;
_segmentZeroClicked = false;
[self.SplitForm removeFromSuperview];
[self.roundFrameForSplit removeFromSuperview];
[self.moveOrderToA removeFromSuperview];
[self.moveOrderToB removeFromSuperview];
[[_segmentControlTableFunctions.subviews objectAtIndex:4] setTintColor:originalColor];
[[_segmentControlTableFunctions.subviews objectAtIndex:1] setTintColor:newSelectedTintColor];
[[_segmentControlTableFunctions.subviews objectAtIndex:2] setTintColor:originalColor];
[[_segmentControlTableFunctions.subviews objectAtIndex:3] setTintColor:originalColor];
wait((int*)1000);
[self removeAllTables];
[self displayTables:[Globals sharedInstance].StartUp.Tables];
_segmentControlTableFunctions.selectedSegmentIndex = UISegmentedControlNoSegment;
[NSTimer scheduledTimerWithTimeInterval: 0.2
target: self
selector: @selector (changeToOriginalColor)
userInfo: nil
repeats: NO];
self.tableManagement.scrollEnabled = YES;
}else if ([[_segmentControlTableFunctions.subviews objectAtIndex:0]isSelected] ){
[[_segmentControlTableFunctions.subviews objectAtIndex:0] setTintColor:originalColor];
if(_segmentControlTableFunctions.selectedSegmentIndex == 0 && _segmentZeroClicked)
{
[self Normal];
return;
}else
{
[self magnify];
return;
}
}