LoginSignup
3
3

More than 5 years have passed since last update.

設定画面で文字入力をした時に改行でキーボードを閉じる方法

Posted at

Tweakで何かしらユーザーが文字列を入力して設定に反映させるとき、キーボードを閉じる必要があります。

今回は簡単にキーボードの改行(return)で、キーボードを閉じる方法を紹介します。

PreferenceBundles

Resourcesフォルダに必要なファイルを入れますが、設定用のplistで文字入力する部分を作成します。

NotifyWifi.plist
<dict>
            <key>PostNotification</key>
            <string>com.ichitaso.NotifyWiFi.preferencechanged</string>
            <key>cell</key>
            <string>PSEditTextCell</string>
            <key>cellClass</key>
            <string>NWEditTextCell</string>
            <key>default</key>
            <string></string>
            <key>defaults</key>
            <string>com.ichitaso.NotifyWiFi</string>
            <key>key</key>
            <string>whiteList1</string>
            <key>label</key>
            <string>White SSID 1</string>
            <key>placeholder</key>
            <string></string>
</dict>

key:cellは「PSEditTextCell」にします。

そこにcellClassを追加します。今回は、NWEditTextCellという名前で入力しておきます。

設定側でのコード

Preference.m
@interface NWEditTextCell : PSEditableTableCell
@end
@implementation NWEditTextCell
- (BOOL)textFieldShouldReturn:(id)arg1
{
    return YES;
}
@end

これを「PreferenceLoader」のxxx.mないしxxx.mmファイルに追記することによって、改行を押した時にキーボードが閉じて設定が反映されるようになります。

ポイントは、cellClassと同じ名前でクラスを記述して下さい。

簡単ですがちょっとした気遣いになりますね!

以上で私の「iOS Jailbreaking Advent Calendar 2015」はおしまいです。

ありがとうございました!

3
3
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3