I think the following image can describe the problem pretty well... https://www.dropbox.com/s/pd1syth3gce6qh7/ios_uimenucontroller.png
I also copy corresponding code part here:
CGPoint point = [sender locationInView:self];
selectedLine = [self lineAtPoint:point];
if(selectedLine) {
[self becomeFirstResponder];
UIMenuController *menuController = [[UIMenuController sharedMenuController] retain];
NSLog(@"count: %d", [[menuController menuItems] count]);
UIMenuItem *menuItem = [[UIMenuItem alloc] initWithTitle:@"???" action:@selector(delete:)];
[menuController setMenuItems:[NSArray arrayWithObjects: menuItem, nil]];
NSLog(@"count: %d", [[menuController menuItems] count]);
for (UIMenuItem *item in [menuController menuItems]) {
NSLog(@"%@", [item title]);
}
[menuController setTargetRect:CGRectMake(point.x, point.y, 2, 2) inView:self];
[menuController setMenuVisible:YES animated:YES];
[menuController release];
[menuItem release];
} else {
[[UIMenuController sharedMenuController] setMenuVisible:NO animated:YES];
}
[linesInProcess removeAllObjects];
[self setNeedsDisplay];
Console output:
2012-10-15 14:02:16.450 TouchTracker[8808:c07] Tap
2012-10-15 14:02:16.455 TouchTracker[8808:c07] count: 0
2012-10-15 14:02:16.455 TouchTracker[8808:c07] count: 1
2012-10-15 14:02:16.456 TouchTracker[8808:c07] ???
2012-10-15 14:02:16.459 TouchTracker[8808:c07] line released
Only one UIMenuItem is added to UIMenuController, and only one in the menuItems NSArray during runtime, but two menu items are appear in the simulator.
If I click on Delete item, it'll send delete: message to self. Actually the title was "Delete" previously, and it looks like it's cached somehow.
Already tried to Reset Content and Settings on iPhone Simulator. Also deleted the content of the DerivedData folder... no solution yet. Will also test on a device soon.
Do you have any idea?
Here you can find the complete project: https://www.dropbox.com/s/wg9ol63aa05px26/TouchTracker.zip
Thanks in advance, Gabor Orosz
The "Delete" is a system menu item that is always visible. Your custom menu items are added to that. From the UIMenuController Class Reference:
The Delete menu item was added to the set of system menu items. Tapping it invokes the UIResponderStandardEditActions action method delete:, also added in iOS 3.2.