2015-10-20 15 views
0

我有一個tableview控制器,並且單元格中的文本處於「基本」樣式。我只是輸入了我想要的文本,它給了我基本樣式的標籤......我現在如何讓用戶能夠按住文本並能夠將文本複製到剪貼板?在tableview中複製文本(swift)

我能夠找到答案這個問題的objective-c,但不適合swift。我認爲這可能是在檢查員,我的問題的答案。但是我在檢查員中找不到任何可以讓我這樣做的東西,除非我在不注意的情況下跳過它。

我有一個真實的設備和模擬器複製從標籤數據

+0

歡迎來到Stack Overflow。我已經修復了您的帖子中的一些英文問題。請提供您的代碼示例。 –

回答

0

更好的辦法上測試使用的UITableView的默認方法:在迅速

-(void)tableView:(UITableView*)tableView performAction:(SEL)action forRowAtIndexPath:(NSIndexPath*)indexPath withSender:(id)sender; 
-(BOOL)tableView:(UITableView*)tableView canPerformAction:(SEL)action forRowAtIndexPath:(NSIndexPath*)indexPath withSender:(id)sender; 
-(BOOL)tableView:(UITableView*)tableView shouldShowMenuForRowAtIndexPath:(NSIndexPath*)indexPath; 

及其等價物:

override func tableView(_ tableView: UITableView, canPerformAction action: 
Selector, forRowAt indexPath: IndexPath, withSender sender: Any?) -> Bool { 
    if (action.description == "copy:") { 
     return true 
    } else { 
     return false 
    } 
} 

override func tableView(_ tableView: UITableView, performAction action: Selector, forRowAt indexPath: IndexPath, withSender sender: Any?) { 
    if (action.description == "copy:") { 
     //... 
    } 
} 

override func tableView(_ tableView: UITableView, shouldShowMenuForRowAt indexPath: IndexPath) -> Bool { 
    return true 
}