UIMenuController is not working in ios6 - iphone

I am working on ios6, and am developing one iphone app. In this app I am using UIMenuController for copy option. The Copy option is working fine in ios5, but it is not working in ios6. I can't display the copy option.
Below I have attached my code. Please somebody help me how to solve this issue.
- (BOOL) canPerformAction: (SEL) action withSender: (id) sender
{
if (action == #selector(paste:))
{
return NO;
}
else
{
return (action == #selector(copy:));
}
}

- (BOOL) canPerformAction: (SEL) action withSender: (id) sender
{
if (action == #selector(paste:))
{
return NO;
}
else
{
return (action == #selector(copy:));
}
}
return [super canPerformAction:action withSender:sender];
}
try this, hope it helps!!

Related

Be notified when a UITableViewCell swipe delete is cancelled in iOS 7

I'm using willTransitionToState which notifies me when the right hand delete button is shown. However, this method is not called when the delete is cancelled by tapping outside the cell area. I've also tried tableView:didEndEditingRowAtIndexPath.
The answers found in this question don't work in iOS 7.
The following code works for iOS 7 (not for iOS 6). The iOS 6 solution is this.
- (void)layoutSubviews
{
[super layoutSubviews];
[self detectDeleteButtonState];
// it takes some time for delete button to disappear
[self performSelector:#selector(detectDeleteButtonState) withObject:self afterDelay:1.0];
}
- (void)detectDeleteButtonState
{
BOOL isDeleteButtonPresent = [self isDeleteButtonPresent:self.subviews];
if (isDeleteButtonPresent) {
NSLog(#"delete button is shown");
} else {
NSLog(#"delete button is gone");
}
}
-(BOOL)isDeleteButtonPresent:(NSArray*)subviews
{
for (UIView *subview in subviews)
{
if ([NSStringFromClass([subview class]) isEqualToString:#"UITableViewCellDeleteConfirmationView"])
{
return [subview isHidden] == NO;
}
if([subview.subviews count] > 0){
return [self isDeleteButtonPresent:subview.subviews];
}
}
return NO;
}

iOS disable cut/copy in iPhone

Can I disable cut/copy in an iPhone application that displays some text via a label or what not? This data is purchased and I don't want them passing it around.
Really you should solve this some other way. What's stopping a user from simply writing down the text? But, for the sake of answering the question:
For a UITextView override the canBecomeFirstResponder function:
- (BOOL)canBecomeFirstResponder {
return NO;
}
And for a UITextField override canPerformAction:withSender:
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
if (action == #selector(paste:))
return NO;
return [super canPerformAction:action withSender:sender];
}

UIWebView shows word suggest menu when user touches a word

I am making a rich text editor app. When app started, UIWebView loads a html file which contains a content editable div.
When I touch a word, UIWebView shows a menu suggest some words instead of selected word. How can I turn off this menu?
That's what I say:
http://i.stack.imgur.com/Xu4A9.png
This is my code:
- (void)viewDidLoad
{
webText=nil;
NSString *path = [[NSBundle mainBundle] pathForResource:#"index" ofType:#"html"];
[self.editor loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:path]]];
self.editor.delegate=self;
[super viewDidLoad];
}
-(BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
if (action == #selector(defineSelection:))
{
return NO;
}
else if (action == #selector(translateSelection:))
{
return NO;
}
else if (action == #selector(copy:))
{
return NO;
}
return [super canPerformAction:action withSender:sender];
}
Here you have to return NO for all the specific methods the menu controller performs.
-(BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
if (action == #selector(defineSelection:))
{
return NO;
}
else if (action == #selector(translateSelection:))
{
return NO;
}
else if (action == #selector(copy:))
{
return NO;
}
return [super canPerformAction:action withSender:sender];
}
Hope this helps .

Disabling menu on tap of UITextField

How do we disable Cut-Copy-Paste or Select-SelectAll menu when tapped on a UITextField. I tried with below code but it did not work.
if ([UIMenuController sharedMenuController]) {
[UIMenuController sharedMenuController].menuVisible = NO;
}
Make a subclass if UITextView and implement this function
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender {
if (action == #selector(paste:) || action == #selector(copy:))//and put other actions also
return NO;
return [super canPerformAction:action withSender:sender];
}
canBecomeFirstResponderhere should do the trick. make sure you delegate your UITextField
- (BOOL)canBecomeFirstResponder {
return NO;
}

How to restrict Copy, Paste for UITextField in iPhone?

i want to restrict the copy or Paste option for particular UITextfield in my Application.
Add the following piece of code in the implementation file of the view controller which containing the UITextField
-(BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
UIMenuController *menuController = [UIMenuController sharedMenuController];
if (menuController) {
[UIMenuController sharedMenuController].menuVisible = NO;
}
return NO;
}
OR
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
if (action == #selector(paste:) // or #selector(copy:)
return NO;
return [super canPerformAction:action withSender:sender];
}
Create a subclass of UITextField.
In that subclass, implement
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender {
if (sel_isEqual(action, #selector(copy:))) //#selector(paste:) {
return NO;
}
return [super canPerformAction:action withSender:sender];
}
Then use this subclass for the field that you don't want to be able to copy in, and use a regular UITextField for the one that you can copy from.
Refer this URL for more info:-
iPhone – Disable the Cut/Copy/Paste Menu on UITextField
UIResponder
iPhone SDK Development
You can implement it like this:
-(BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
if (action == #selector(paste:)) {
return NO;
}
return [super canPerformAction:action withSender:sender];
}
Otherwise you can write:
- (BOOL)canBecomeFirstResponder {
return NO;
}
To make your UITextField non-editable.