好的,这就是正在发生的事情。如果我在我拥有的 5 个段中单击段“0”(最右边,因为 ios 中的段控制将 0 计为右边),它第一次通过正确的段,即“0”。但是我第二次点击它,它认为我点击了第 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;
}
}