2012-09-10 32 views
1

我正在爲基於消息的iPhone應用程序工作。在我的應用程序中,我在UITextView中加載了消息內容,並在UITextView上添加了UIImage。如何通過暫停選擇所有UITextview內容並通過編程方式顯示覆制選項iphone?

現在我想通過舉辦的UITextView 選擇所有UITextView的內容和顯示覆制選項給用戶。目前當用戶hold UITextView some of the content only selecting

任何人都可以幫我做到這一點?提前致謝。

編輯:

在UITableView的CellForRowAtIndexPath委託

customMessageTextView = [[MessageTextView alloc] initWithFrame:CGRectZero]; 
    customMessageTextView.tag = 100; 
    UIFont *font = [UIFont fontWithName:@"Helvetica" size:15]; 
    customMessageTextView.font = font; 
    customMessageTextView.scrollEnabled = NO; 
    customMessageTextView.delegate = self; 
    customMessageTextView.dataDetectorTypes = UIDataDetectorTypeLink; 
    [cell.contentView addSubview:customMessageTextView]; 
    [customMessageTextView sizeToFit]; 

    for (UIGestureRecognizer *recognizer in customMessageTextView.gestureRecognizers) 
    { 
     if ([recognizer isKindOfClass:[UILongPressGestureRecognizer class]]) 
     { 
      recognizer.enabled = NO; 
     } 
    } 


    UILongPressGestureRecognizer *myLongPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(selectAllTextFromCustomMessageTextView)]; 
    [customMessageTextView addGestureRecognizer:myLongPressRecognizer]; 
    [myLongPressRecognizer release]; 

UILongPressGestureRecognizer行動:

-(void) selectAllTextFromCustomMessageTextView 
{ 
    NSLog(@"Select All Text Messages"); 
    customMessageTextView.selectedRange = NSMakeRange(0, customMessageTextView.text.length); 
} 

回答

2

如果我理解正確,你要禁用的標準行爲在UITextView控股時(即放大鏡等)。也許你甚至已經禁用了編輯選項。如果是這樣,你應該只需要添加一個UILongPressGestureRecognizerUITextView。您可能必須禁用默認內置於UITextViewUILongPressGestureRecognizer。你可以找到一種方法來做到這一點here

然後在您的UILongPressGestureRecognizer操作方法只需在視圖中選擇所有文本:

[textView selectAll:self]; 

注意,這將彈出複製/剪切/粘貼菜單。但是,如果您的文本視圖確實禁用了用戶編輯,則該菜單將僅包含複製

+0

感謝您的回答。我正在嘗試你的指示。我會讓你知道結果。再次感謝。 – Gopinath

+0

它不適合我。我會發布我的代碼。你可以幫我嗎?謝謝。 – Gopinath

+0

你是對的,設置'selectedRange'屬性不起作用。我用一種應該可以工作的方法更新了我的答案(這次我已經測試過了)。 – pajevic

相關問題