开发者

Handling the paste event in a UIViewController

I would like to handle the paste event in my UIViewCont开发者_StackOverflowroller for my attached UITextView, so that if the pasted data is text or html it should paste the data in as normal and as it already does, but if it is something else like a image or pdf or anything, I would like to store the data locally in another way and not paste it into the UITextView (as it can not do this).

How would I go around doing this? In the only example I can find from Apple, they know the type of the data they paste. Even getting my "-(void)paste:(id)sender" method in my controller to get called when there is a paste event in my UITextView escapes me.

Thank you


You can use the method canReadObjectForClasses:options: to test for something without actually retrieving the value.

For example, testing for strings:

NSArray *classes = [NSArray arrayWithObject:[NSString class]];
NSDictionary *options = [NSDictionary dictionary];

if ([[NSPasteboard generalPasteboard] canReadObjectForClasses:classes options:options]) {
    NSLog(@"yup, there is a string in here");
}

Update:

You're checking for all objects in the paste board this way, just add any class that you expect on the array.

NSArray *classes = [NSArray arrayWithObjects:[NSURL class], [NSString class], nil];

Use the UIResponderStandardEditActions protocol to implement the paste method.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜