开发者

Is there a way to manipulate the keyboard programmatically for the iPhone?

I have a simple Application for the iPhone which has a button and uses MFMessageComposeViewControler to send a text message. When the user presses the button, the MFMessageComposeViewController pulls up the keyboard and the user is able to send an sms, as expecte开发者_Python百科d.

I'd like to be able to manipulate that keyboard. In other words, for example, if the user goes to send the text "how are you" I'd like to be able to, in my program, recognize the phrase "how are you" and change it to "how is life" or change it to whatever. Is this possible?


To make a view controller a delegate for two other things, you define it like the below in the header file:

@interface AViewController : UIViewController <UITextFieldDelegate, MFMessageComposeViewControllerDelegate> {

    // Variable Definitions for your
    // textfield and uibutton


}

// Method Declarations here.
// You don't need to define the delegate methods,
// Just implement them in your .m file.

@end

Then use the delegate methods I talked about below to intercept the text that has / is being input.


EDIT: I should have read your question more thoroughly before answering.

There is no legal way of editing the keyboard in iOS on the iPhone. As per my answer below, you want to be able to "intercept" the textfield/textview used by the MFMessageComposeViewController.

From studying the MFMessageComposeViewController class (and it's delegate) there is no public way to "intercept" the message being input by the user. The best you can do is to start the user off with some text for their message.

If you wanted to achieve this, which maybe possible through sub-classing MFMessageComposeViewController (and finding out what the textfield/view instance variable is), it is quite likely that Apple may not accept your application to the App Store.


Old Answer: If you want to do something like this you need to look at the delegate methods for the UITextField (UITextFieldDelegate). There are number of different approaches you could take.

textField:shouldChangeCharactersInRange:replacementString: - implementing this method will allow you to change characters as it they are entered.

textFieldDidEndEditing: - implementing this will allow you to "intercept" the textfield that has been edited. In turn you can use the textfield that is passed into the method to get the string and manipulate or change words as you wish.

If you are using a UITextView, it also has its own delegate (UITextViewDelegate) with very similar methods you can implement to intercept the text entered by the user.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜