カーソルが現在ある場所にテキストを貼り付けようとしています。私はそれが言うことをしようとしてきました:-http: //dev.ragfield.com/2009/09/insert-text-at-current-cursor-location.html
主な取引は、テキストフィールドがカスタムセルの真ん中にあるため、textbox1.text(など)に移動できないことです。カーソルがある場所にテキストを追加したいだけです(キーボードのカスタムキーを押したとき)。
-テキストボックスに小数を貼り付けたいだけです...
私が得るエラーは次のとおりです。
2010-05-15 22:37:20.797 PageControl [37962:207] *-[MyDetailControllerの貼り付け:]:認識されないセレクターがインスタンス0x1973d10に送信されました2010-05-15 22:37:20.797 PageControl [37962:207]*アプリの終了期限キャッチされない例外'NSInvalidArgumentException'、理由:'***-[MyDetailControllerペースト:]:認識されないセレクターがインスタンス0x1973d10に送信されました'
注:テキストフィールドタグにアクセスできます(それが役立つ場合)
私はObjective-cの初心者段階を少し過ぎていますが、それでも素晴らしいとは言えません。私のコードは現在以下にあり、https://gist.github.com/d634329e5ddf52945989にあります
皆さんありがとう。
MyDetailController.h
@interface MyDetailController : UITableViewController <UITextFieldDelegate,UINavigationControllerDelegate>
{
//...(lots in here)
}
@end
@interface UIResponder(UIResponderInsertTextAdditions)
- (void) insertText: (NSString*) text;
@end
MyDetailController.m
@implementation MyDetailController
//.... (lots in here)
- (void)addDecimal:(NSNotification *)notification {
// Apend the Decimal to the TextField.
//savedAmount.text = [savedAmount.text stringByAppendingString:@"."];
NSLog(@"Decimal Pressed");
NSLog(@"tagClicked: %d",tagClicked);
switch (tagClicked) {
case 7:
//savedAmount.text = [savedAmount.text stringByAppendingString:@"."];
break;
case 8:
//goalAmount.text = [goalAmount.text stringByAppendingString:@"."];
break;
case 9:
//incrementAmount.text = [incrementAmount.text stringByAppendingString:@"."];
break;
case 10:
//incrementAmount.text = [incrementAmount.text stringByAppendingString:@"."];
break;
}
[self insertText:@"."];
}
-(void)textFieldDidBeginEditing:(UITextField *)textfield{
//UITextField *theCell = (UITextField *)sender;
tagClicked = textfield.tag;
NSLog(@"textfield changed. tagClicked: %d",tagClicked);
}
@end
@implementation UIResponder(UIResponderInsertTextAdditions)
- (void) insertText: (NSString*) text
{
// Get a refererence to the system pasteboard because that's
// the only one @selector(paste:) will use.
UIPasteboard* generalPasteboard = [UIPasteboard generalPasteboard];
// Save a copy of the system pasteboard's items
// so we can restore them later.
NSArray* items = [generalPasteboard.items copy];
// Set the contents of the system pasteboard
// to the text we wish to insert.
generalPasteboard.string = text;
// Tell this responder to paste the contents of the
// system pasteboard at the current cursor location.
[self paste: self];
// Restore the system pasteboard to its original items.
generalPasteboard.items = items;
// Free the items array we copied earlier.
[items release];
}
@end