2014年3月22日土曜日

【Objective-C】Viewに追加されたUITextFiledのタグを指定して値を取得する方法

親画面に複数のテキストフィールドがあり、入力を子画面のポップアップでさせた場合に、どのテキストフィールドに入力値を反映させるかの判定に使用出来ます。このやり方を知る前はswitch case tagで分岐して、代入先を静的に設定していました。

□ 前提
テキストフィールドにtagを設定しておく。
テキストフィールドの編集時にlastTagに該当テキストフィールドのtagを設定しておく。

□ サンプルソース
子画面の入力後のdelegateメソッド(updateData)でViewにtag指定してUITextFieldを取得します


- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
    lastTag = textField.tag;
}

- (void)updateData :(NSString *) dataValue{
    // viewからtagを検索して
    UITextField* textField = (UITextField*) [self.view viewWithTag:lastTag];
    textField.text = dataValue;

}


1 件のコメント:

  1. Hello dear Developer
    We have noticed that your app SpaceBoxWar continues to do well on the App Store. Given the nature of your product though, we believe that it has the potential to reach even greater sales and download numbers. There are some marketing steps that you can perform to make your app promotion campaign more successful. We can offer you various marketing services for successful promotion of your products:

    • Pre-Launch campaigns
    • Mass Mailing among 10 000 iOS users
    • Guaranteed app Sales/Downloads
    • Guaranteed app reviews by major iOS review sites
    • Press Release & Social Media promotion
    • App Icon and Screenshot design services

    We know very well that the mobile app industry is extremely tough and dynamic. We can provide you with the effective, well directed, and well executed promotional efforts your products require to make them stand out from the crowd and succeed. If you are interested feel free to contact us at any time.

    Best regards,
    Terry Lewis
    BombAppromotion team
    http://www.bombappromotion.com/
    http://twitter.com/BombAppromotion
    http://www.facebook.com/BombAppromotion

    返信削除