最近在公司做一個體現(xiàn)需求溜嗜,具體需求類似于支付寶的一個體現(xiàn)宵膨,在做這個需求的過程中我發(fā)現(xiàn)通過粘貼可以把字符串以及特殊字符粘貼進去,這不符合項目的一個要求炸宵,經(jīng)過研究發(fā)現(xiàn)蘋果提供了這樣一個方法
- (BOOL)canPerformAction:(SEL)action withSender:(nullable id)sender NS_AVAILABLE_IOS(3_0);
//Allows an action to be forwarded to another target. By default checks -canPerformAction:withSender: to either return self, or go up the responder chain.
具體用法如下:
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
if (action == @selector(paste:))//禁止粘貼
return NO;
if (action == @selector(select:))// 禁止選擇
return NO;
if (action == @selector(selectAll:))// 禁止全選
return NO;
return [super canPerformAction:action withSender:sender];
}