0

I am trying to user textDocumentProxy to insert some texts from another view controller which presented from UIInputViewController. I am using NSNotificationCenter to post "SendText" notification, and the KeyboardViewController addObserver to this notification. The first time is working, but when I dismiss the view controller and present again. it's not working. The notification is received. Why it's working the first time, and when I present the ListViewController again, it's not working?

KeyboardViewController.m

- (void)viewDidLoad
{
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sendText:) name:kKeyboardSendTextNotification object:nil];
}

- (void)sendText:(NSNotification *)notif
{
    [self.textDocumentProxy insertText:notif.object];
}

ListViewController.m

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    Place *place = self.collections[indexPath.row];
    NSString *message = [NSString stringWithFormat:@"%@? %@, %@", self.selectedType, place.name, place.mobileUrl];
    [[NSNotificationCenter defaultCenter] postNotificationName:kKeyboardSendTextNotification object:message];
}
yong ho
  • 3,892
  • 9
  • 40
  • 81
  • Did you solve it? If yes, can you please share the way to do it as I am facing the same issue – Sibir May 20 '15 at 07:35

1 Answers1

0

Why are you using notifications for this simple task? You can simply call the insertText: method as-is:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    Place *place = self.collections[indexPath.row];
    NSString *message = [NSString stringWithFormat:@"%@? %@, %@", self.selectedType, place.name, place.mobileUrl];
    [self.textDocumentProxy insertText:message];
}
nurnachman
  • 4,468
  • 2
  • 37
  • 40