custom Copy Responder in iphone - iphone

I have a webview in my application. I want to handle when user copies something from web view, my custom method - should be triggered. I have tried following.
I have placed following method in myViewCtr.m file
-(void)copy:(id)sender{
NSLog(#"hi ! Hello ");
}
But nothing working - what should I do to implement the same ?

You need to implement -copy: on the responder, not on the controller. So you need to subclass UIWebView and override -copy:.

Ahh ! I got something here from this question.
Direct sample from Apple itself.
Theory :)

Related

Screen orientation not changing despite calls to shouldAutorotateToInterfaceOrientation

I would like to add the functionality to change the screen orientation for various views in my app. Having read various tutorials, I implemented the shouldAutorotateToInterfaceOrientation method in each of my view controllers, and got each of them to return yes, as well as log the call to the console, like this:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
NSLog(#"shouldAutorotateToInterfaceOrientation called");
return YES;
}
When I run this on the simulator and change the orientation, I get the log message but nothing on the screen changes. I've tried to find how this could happen but everywhere I've looked says problems are associated with the method not being called, even though it is in my case. Any ideas?
Thanks
I need to know that in your code are you using every views by code or .xib.
Also you need to set autorisizing property for every component...
Solved it: there was a direct UIViewController object being initialised in the code, and changing it to my own simple base class solved the issue. Thanks for the advice!

iOS ViewController After Load Method

I'm trying to find a method thats called once everything has been loaded and displayed. The reason I want to do this is because I have some images that take some time to load in so instead of showing them a black screen I want to show a loading page and then call a setup method.
However the only methods I can find are called before the views come into view...
I am probably being really dumb..
Any help would be great.
Disco
You can use
- (void)viewWillLoad;
and
- (void)viewDidAppear:(BOOL)animated;
to do what you need.
How about
- (void)viewDidAppear:(BOOL)animated;

iPhone / Objective C - Communication between ViewController / best way to implement?

I'm doing a iPhone app.
I created my own SwitchViewController Class (linked to the App-Delegate) which actually just
changes the various other Views / ViewControllers (e.g ViewA, ViewB) while the app is running.
When I know recieve a tap-gesture in the ViewController-A I would like to trigger a method (eg. switchViews:(id)sender) in the SwitchViewController Class.
What would the best way to do this?
Must I initiate ViewA with a object-reference to SwitchViewController?
Delegate? What would be the best way?
When I add a button to ViewA its no problem, then I just can connect it to the IBOutlet. But programmatically?
Thanks,
Stefan
Sounds like a prime example for using the NSNotificationCenter.
Used actually the responder chain, and recieved the tap in the switchViewController.

Detect when a user clicks the paste button in a UITextView

I am having quite a issue trying to change the cut/copy/paste behavior of the UITextView.
What I want to achieve is: detect when the user has pasted some text into the UITextView. When I detect this I will then check the data and do my thing.
According to the documents, I found out about UIResponder.
So I created an simple class that inherits UITextView.
in the .m file I create 1 function called.
-(void) paste:(id)sender{
NSLog(#"paste button was pressed do something");
}
But for some reason it never seems to fire. I could get the select statement working and tracing data.
-(void) select:(id)sender
1. Is this the correct way to detect Paste in a UITextView?
2. Right now I am tracking buy how many Characters UITextView changes and if its greater than one char then I suspect that it could be a paste operation. But since the iPhone can autocomplete words eg Wedn (goes to Wednesday) its possibly not a paste operation.
In Interface Builder, I selected my textView in my NIB file, and selected its "Class Identity" to my nearly created class before and I know that this file was working as a subclass but it just would not respond to the Paste event.
thanks.
UITextView has a view that handles the cut, copy, paste. It's UIWebDocumentView. So if UITextView is the first responder, UIWebDocumentView will get it first instead of your implementation. I would like to overwrite these functions so this is very frustrating.
Same thing happens to me too. Select (and copy sometimes) gets called but paste never.
I have simulated the behavior using textViewDidChange where I always verify the difference between the current text and the previous one. If there are more letters different and the text.length is bigger than it must have been pasted.
Hope Apple will fix this.
In case somebody still needs short and easy solution I'll share mine. I use wonderfull NSObject+REResponder category from REKit project. The solution is as easy as this:
- (void)hookMessageTextFieldPasteAction
{
void (^textFieldDidPasteBlock)(id receiver, id sender) = ^(id receiver, id sender)
{
NSLog(#"paste hook");
};
[self.messageTextField respondsToSelector:#selector(paste:) withKey:nil usingBlock:textFieldDidPasteBlock];
}
Yes your above code for paste is correct according to Apple's Documentation which refers to it here.
- (void)paste:(id)sender
I suspect you are implementing it in the wrong file. You should be implementing it in a file that is part of the 1st Responder chain. Have you subclassed the UITextView or are you using a vanilla one in your ViewController?
Hmmm I think the problem is that you may need to make your UITextView subclass become the delegate in order for the delegate method to work, because it's not by the looks of things. I'll try to find how i did that before.
Okay think i found it. I think you need to do this on your subclassed UITextField class:
#interface mySpecialTextFieldClass : NSObject <UITextFieldDelegate>
{
}
Adding that onto the end should work, give it a try!
What it does is makes your subclass become an object of a type that the delegate can send a notification to...it's polymorphism, unless someone wants to correct me here :)
One last thing to try John, in the ViewController which contains the IBOutlet to the UITextView, try calling this method on the instance of the UITextView:
[myUITextView setDelegate:self];
Just to throw something completely random in there try setting it to become first responder.
[myUITextView becomeFirstResponder];
This is called programming in the dark kiddies! And is a very bad way to program, but I admit I do it and sometimes it pays off :P lol.

Call an onclick method from one view to another iphoneprogess hub iphone sdk

I have a view with a button which downloads files when clicked.
Question I have is is it possible to call that click method from another view>
THanks
You have a method there. Something like onBtnClk. You can create in another view an instance of your viewController, that contains this method and send [myViewController onBtnClk].
This may be a good case to have some other class(maybe a singleton?) handle downloads, then have your click: method interact with the downloading class.
I know that everyone hates singletons, but this may be a good time to use one.