0

ユーザーが a をクリックしたUIPickerViewときに a を表示しようとしています。また、選択を送信してキャンセルするためのボタンを備えたツールバーを上部に配置しUITextFieldたいと考えています。UIPickerView

UIPickerViewインターフェイスビルダーで接続する必要がありますか、それともアクションを別の場所に接続する必要がありますか? ビルド時にも警告が表示されます。の下に 1 つの警告がありresignFirstResponderます。それは言います:

agehide インスタンス変数のローカル宣言

さまざまな変数について、上記と同様の警告がさらにいくつかあります。

別の警告は次のとおりです。

クラス「PracticePickerViewController」は「UIActionsheetDelegate」プロトコルを実装していません。

ここに私.hのファイルがあり.mます:

.h

#import <UIKit/UIKit.h>

@interface PracticePickerViewController : UIViewController <UITextFieldDelegate>{

    IBOutlet UITextField *age;
    IBOutlet UIPickerView *agePickerView;
    IBOutlet UIActionSheet *actionSheet;
    IBOutlet UIToolbar *pickerToolbar;

}


@end

.m

#import "PracticePickerViewController.h"

@implementation PracticePickerViewController

-(void)textFieldDidBeginEditing:(UITextField *)age{
    [age resignFirstResponder];

    actionSheet = [[UIActionSheet alloc] initWithTitle:@"Pick Your Age" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];

    [actionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent];
    CGRect pickerFrame = CGRectMake(0,40,0,0);

    UIPickerView *agePickerView = [[UIPickerView alloc] initWithFrame:pickerFrame];
    agePickerView.showsSelectionIndicator = YES;
    agePickerView.dataSource = self;
    agePickerView.delegate = self;
    [actionSheet addSubview:agePickerView];

    pickerToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0,0,320,44)];
    pickerToolbar.barStyle = UIBarStyleBlackOpaque;
    [pickerToolbar sizeToFit];

    NSMutableArray *barItems = [[NSMutableArray alloc] init];

    UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
    [barItems addObject:flexSpace];

    UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneButtonPressed:)];
    [barItems addObject:doneBtn];

    UIBarButtonItem *cancelBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelButtonPressed:)];
    [barItems addObject:cancelBtn];

    [pickerToolbar setItems:barItems animated:YES];

    [actionSheet addSubview:pickerToolbar];
    [actionSheet addSubview:agePickerView];
    [actionSheet showInView:self.view];
    [actionSheet setBounds:CGRectMake(0,0,320,485)];

}
4

1 に答える 1

0

年齢のローカル宣言はインスタンス変数を隠します

これは、クラス変数で既に使用されている変数名を定義したことを意味します (したがって、この場合、クラスのどこかで宣言した可能性がありますが、コンパイラが混乱するため、このクラスでUITextField *age変数名を再利用することはできません)。ageクラス変数を使用します)。

クラス「PracticePickerViewController」は「UIActionsheetDelegate」プロトコルを実装していません。

PracticePickerViewController をUIActionsheetDelegate. これを行うには、インターフェイス ヘッダー (PracticePickerViewController.h) を次のように変更します。

@interface PracticePickerViewController : UIViewController <UITextFieldDelegate, UIActionsheetDelegate>{

必要なデリゲート メソッドも実装することを忘れないでください。

最後に、 ActionSheetPicker プロジェクトを確認することを強くお勧めします。
これは、実装しようとしている機能を正確に備えたドロップイン クラスであるため、現在のコードをそれで置き換えるか、それを参照として使用して、UIPickerView 内に埋め込まれた ActionSheet を正しく実装する方法を確認できます。それがすべて役立つことを願っています!

于 2012-07-11T03:32:53.003 に答える