0

これが起こっていることです。私が持っている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;
        }
    }
4

3 に答える 3

1

サブビューは静的ではありません。タブを選択すると、ビューの階層が変更され (グロスを追加したり、物事を移動したり、その他のことを行ったり)、インデックスがあなたが思っているものではなくなったのではないかと思います。誰かがコメントしたように、選択したセグメント インデックスが最初に残されます。サブビューのインデックスに基づくのではなく、選択したセグメント インデックスを使用するように切り替えることを強くお勧めします。選択したインデックスから返される値は常に正しいものになります。

于 2013-06-04T16:22:17.470 に答える
0

不思議に思っている人のために、これは私にとってはうまくいきました。:)

                for (int i = 0; i < self.segmentControlTableFunctions.subviews.count; i++)
            {
                if ([[self.segmentControlTableFunctions.subviews objectAtIndex:i]isSelected] )
                {
                    [[self.segmentControlTableFunctions.subviews objectAtIndex:i] setTintColor:newSelectedTintColor];
                }
                else
                {
                    [[self.segmentControlTableFunctions.subviews objectAtIndex:i] setTintColor:originalColor];
                }
            }
于 2013-06-07T18:59:21.350 に答える