0

検索ビュー コントローラーに、次のメソッドを呼び出すボタンがあり、UIActionSheet2 つUISegmentedControlの s (検索設定の選択に使用) を作成します。ユーザーが最初のセグメント化されたコントロールで特定のボタンを選択したときに、2 番目のセグメント化されたコントロールを無効 () にしたいsetEnabled:NO。問題は、再描画されないことです (したがって、無効になることはありません)。UIActionSheet を作成するときに最初に Enabled:NO を設定すると、最初は正しく無効になります。

を呼び出して、2 番目のセグメント化されたコントロールとアクション シートの両方で再描画を強制しようとしましたが、うまくいきませ[UIView setNeedsDisplay]ん。

また、2 番目のセグメント化されたコントロールで removeFromSuperview を試しました。

これは組み込みの UIActionSheet では不可能ですか? または、検索設定を表示するためのより良い方法はありますか? これは iOS5 用にコーディングされた iPhone アプリです。ポップオーバーは iPhone では機能しません。私が考えることができる他の方法は、設定を独自のビューに表示することですが、それは避けたいと思います。

-(void)onSettingsButtonClick:(id)sender
{
    // display segmented button views on actionSheet

    UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"Search Settings" delegate:self cancelButtonTitle:@"Close" destructiveButtonTitle:nil otherButtonTitles:nil, nil];
    sheet.actionSheetStyle = UIActionSheetStyleDefault;

    UISegmentedControl * segFullTextOrTags = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"Tags", @"Full Text", @"Users", nil]];
    [segFullTextOrTags addTarget:self action:@selector(onSegFullTextOrTagsClicked:) forControlEvents:UIControlEventValueChanged];
    [segFullTextOrTags setSegmentedControlStyle:UISegmentedControlStyleBar];
    [segFullTextOrTags setTag:100];

    UISegmentedControl * segType2 = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"All Actions", @"Discussions", @"Responses", @"Comments", nil]];
    [segType2 addTarget:self action:@selector(onSegType2Clicked:) forControlEvents:UIControlEventValueChanged];
    [segType2 setSegmentedControlStyle:UISegmentedControlStyleBar];
    [segType2 setTag:101];

    [sheet showFromTabBar:self.tabBarController.tabBar];

    // code that expands the action sheet height and adjusts the view positions is omitted here

    // add the additional views to the actionSheet
    [sheet addSubview:segFullTextOrTags];
    [sheet addSubview:segType2];
}

-(void)onSegFullTextOrTagsClicked:(id)sender
{
    [self updateSettingsUI:(UIActionSheet*)sender];
}

-(void)onSegType2Clicked:(id)sender
{
    [self updateSettingsUI:(UIActionSheet*)sender];
}

-(void)updateSettingsUI:(UIActionSheet*)actionSheet
{
    UISegmentedControl * segFullTextOrTags = (UISegmentedControl*)[actionSheet viewWithTag:100];
    UISegmentedControl * segType2 = (UISegmentedControl*)[actionSheet viewWithTag:101];

    if (segFullTextOrTags.selectedSegmentIndex == 2) // users
    {
        // disable 2nd segmented button control
        [segType2 setEnabled:NO];
    }
    else
    {
        // enable 2nd segmented button control
        [segType2 setEnabled:YES];
    }

    // doesn't work...
    [segType2 setNeedsDisplay];
    [actionSheet setNeedsDisplay];
}
4

1 に答える 1

1

UIActionSheet は、ユーザーに設定ビューを表示するための適切なコントロールではないと思います。

クラスリファレンスドキュメントから:

UIActionSheet クラスを使用して、特定のタスクを続行する方法の一連の選択肢をユーザーに提示します。アクション シートを使用して、潜在的に危険なアクションを確認するようユーザーに促すこともできます。アクション シートには、オプションのタイトルと 1 つ以上のボタンが含まれており、それぞれが実行するアクションに対応しています。

代わりに、UIViewController サブクラスを作成し、それをモーダルまたはナビゲーション コントローラーで提示する必要があります。

setEnabledなぜあなたのコードで機能しないのかわかりません。setNeedsDisplayコントロールはそれ自体を再描画する必要があります。updateSettingsUI と onSettingsButtonClick の segType2 が同じオブジェクトかどうかを確認します。

于 2012-06-18T22:11:40.667 に答える