views:

168

answers:

0

EDIT: I have modified Apple's colored tile example by adding

UIMenuController *theMenu = [UIMenuController sharedMenuController];
theMenu.arrowDirection = UIMenuControllerArrowLeft;

to applicationDidFinishLaunching and adding a UITextView right next to the reset button. If I double click on a colored tile, the copy paste menu correctly shows up with a left arrow. However, if I double click on the text in the UITextView, it totally ignores anything I set on the global copy paste menu. Is it possible that the UITextView has its own copy paste menu system separate from the one you get with [UIMenuController sharedMenuController]?

Original post:

My setup is a little convoluted so please bear with me. I have an application with 5 tabs, and inside each tab is a split view. The left side of the split view is a table, and the right side contains a UITextView. I'm attaching a picture to make everything clearer

http://www.maisonikkoku.com/yonder/forNora/firstTab.png (new users cant post images!)

I would like to add a feature where users can click on some word on the right side, select it, and add it to some section in one of the other tabs ( the sections are things like grammar, vocab, and kanji, so its conceivable you may want to add a word from an example sentence in grammar to your kanji list ). Seemed simple enough. I figured I would just add an item to the copy paste menu using UIMenuController's menuItems array like I see being done in examples.

However, this doesn't work as my menu items never actually show up. I tried using variations of the following code

UIMenuItem *menuItem = 
  [[UIMenuItem alloc] initWithTitle:@"Change Color" action:@selector(changeColor:)];
UIMenuController *menuCont = [UIMenuController sharedMenuController];
[menuCont setTargetRect:mTestText.frame inView:mTestText.superview];
menuCont.arrowDirection = UIMenuControllerArrowLeft;
menuCont.menuItems = [NSArray arrayWithObject:menuItem];
[menuCont setMenuVisible:YES animated:YES];

But it never actually adds the item. No matter what happens, if I click on the text on the right side, only the usual copy/paste menu comes up. Maybe I am doing it in the wrong place? Right now in my main application delegate, I have

if( mAddCopyPasteMenuItems )
{
    UIMenuItem *menuItem = 
      [[UIMenuItem alloc] initWithTitle:@"Change Color" action:@selector(changeColor:)];
    UIMenuController *menuCont = [UIMenuController sharedMenuController];
    menuCont.arrowDirection = UIMenuControllerArrowLeft;
    menuCont.menuItems = [NSArray arrayWithObject:menuItem];
    [menuCont setMenuVisible:YES animated:YES];
}
[self.mWindow addSubview:self.mTabBarController.view];
[self.mWindow makeKeyAndVisible];

So, admittedly, I have never seen it done on application startup like that, so maybe you have to do it in some touch ended event like you see in the examples. The problem with that is I just can't get UITextView to receive the touch events. I tried creating a new class that derives from UITextView

@interface BunpouRightSideText : UITextView <UITextViewDelegate>

and then adding all those great touch events callback functions

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [super touchesBegan:touches withEvent:event];
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    [super touchesMoved:touches withEvent:event];
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self.nextResponder touchesEnded: touches withEvent:event]; 
    [super touchesEnded:touches withEvent:event];
}

- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
    [super touchesCancelled:touches withEvent:event];
}

But breakpoints in those functions never seem to get called. Setting BunpouRightSideText's delegate to self and enabling multitouch seems to only make matters worse, as double clicking anywhere on the text disables my ability to click on anything in the whole app until I shut down. I can't even switch tabs.

So to sum it up... what could be causing my new menu items added to the shared menu controller to never show up? Do they have to be added from somewhere specific or am I just missing something somewhere else? And is there a sane way to have a UITextView ( or class that derives from one ) receive touch events without totally screwing the system?

Also if any of you have any ideas on how to do this without using the copy paste menu I am open to suggestions. The only reason I was using it in the first place is that in Japanese there are no spaces between words, so I was hoping to use Apple's useful selection adjusting mechanism to adjust the selected area to the start and end of a word before bringing up the menu with the additional items ( add to other section, find in other section )

Thanks in advance for any pointers or advice!