0

ストーリーボードでXCode4を使用して作成されたiPadアプリがあります。次のように定義されたインターフェイスを持つUITableViewControllerがあります。

@interface CustomerViewController : UITableViewController <UITextFieldDelegate> 

.mファイルには、次のようなコードスニペットがあります。

- (BOOL) textFieldShouldReturn:(UITextField *)textField  {

if(textField == businessName)  {
    [email becomeFirstResponder];
    return true;
}

メソッド'textFieldShouldReturn'は実行されません。他に何をする必要がありますか?(ところで...私はこれをiPadアプリで動作させることができませんでしたが、iPhoneアプリでは常に成功しました)

4

2 に答える 2

3

In the textFieldShouldReturn method, you're testing if the textField is equal to businessName. I'm assuming that's a UITextField object, but you have to set the delegate to receive callbacks. Just a simple self.businessName.delegate = self; when you create the TextField.

Another tip, I'd recommend calling it something like businessNameTextField. It's easier to read throughout your code.

于 2012-05-31T21:48:43.093 に答える
1

ビュー コントローラーをテキスト フィールドのデリゲートとして設定する必要があります。プロトコルに準拠していることを宣言するだけでは十分ではありません。iPhone では機能するが iPad では機能しない場合は、デリゲート アウトレットを iPad ストーリーボードにリンクしていない可能性がありますが、iPhone にはリンクしています。

于 2012-05-31T21:31:11.843 に答える