UITableViewCell的子类在选任期间,是否像在地址簿上那样,展示UIMenuController的流行(见屏幕)。
(source: icog.net)
UITableViewCell的子类在选任期间,是否像在地址簿上那样,展示UIMenuController的流行(见屏幕)。
(source: icog.net)
摆在SOS 5号文件之前的方法是让UIMenuController分享经验,确定目标重心和看法,并打电话-setMenuVisible:animated:
。 Remeber to implementing -canPerformAction:withSender:
in les responseer.
“5”后的方法(以前作为无证特征)是,在你的数据来源中采用这三种方法(见)。
-(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;
如今,在5台显示可调用的电文电池板的官方接口。 例例(从表格代表处):
- (BOOL)tableView:(UITableView *)tableView shouldShowMenuForRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES;
}
- (BOOL)tableView:(UITableView *)tableView canPerformAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender
{
return (action == @selector(copy:));
}
- (void)tableView:(UITableView *)tableView performAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender
{
if (action == @selector(copy:)){
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
[[UIPasteboard generalPasteboard] setString:cell.textLabel.text];
}
}
我试图修改UIMenuController的共享控制器,以添加我自己的菜单,我得以添加并获取canPerformAction
的电文,但返回的YES确实没有帮助;我没有能够把我的习惯菜单列入项目。 从我的实验来看,它只看制版、Cut和Paste。 [EDIT 自张贴以来,我学会如何增加习俗菜单。]
请注意,只有在采用所有三种代表方法的情况下,才进行这项工作。
此处为“快速星号”复印件。
func tableView(_ tableView: UITableView, shouldShowMenuForRowAt indexPath: IndexPath) -> Bool {
return (tableView.cellForRow(at: indexPath)?.detailTextLabel?.text) != nil
}
func tableView(_ tableView: UITableView, canPerformAction action: Selector, forRowAt indexPath: IndexPath, withSender sender: Any?) -> Bool {
return action == #selector(copy(_:))
}
func tableView(_ tableView: UITableView, performAction action: Selector, forRowAt indexPath: IndexPath, withSender sender: Any?) {
if action == #selector(copy(_:)) {
let cell = tableView.cellForRow(at: indexPath)
let pasteboard = UIPasteboard.general
pasteboard.string = cell?.detailTextLabel?.text
}
}
页: 1 电池子组可照此办理。
@interface MenuTableViewCell : UITableViewCell {
}
- (IBAction)copy:(id)sender;
- (void)showMenu;
@end
@implementation MenuTableViewCell
- (BOOL)canBecomeFirstResponder {
return YES;
}
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
if (action == @selector(copy:)) {
return YES;
}
return NO;
}
- (IBAction)copy:(id)sender {
}
- (void)showMenu {
[[UIMenuController sharedMenuController] setMenuVisible:NO animated:YES];
[self becomeFirstResponder];
[[UIMenuController sharedMenuController] update];
[[UIMenuController sharedMenuController] setTargetRect:CGRectZero inView:self];
[[UIMenuController sharedMenuController] setMenuVisible:YES animated:YES];
}
@end
友好通话代表方法也一样。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
MenuTableViewCell *cell = (MenuTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[MenuTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell.
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
MenuTableViewCell *cell = (MenuTableViewCell *)[tableView cellForRowAtIndexPath:indexPath];
[cell showMenu];
}
#pragma mark - COPY/PASTE Cell Text via Menu
- (BOOL)tableView:(UITableView *)tableView shouldShowMenuForRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES;
}
- (BOOL)tableView:(UITableView *)tableView canPerformAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender
{
return (action == @selector(copy:));
}
- (void)tableView:(UITableView *)tableView performAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender
{
if (action == @selector(copy:))
{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
UIPasteboard *pasteBoard = [UIPasteboard generalPasteboard];
[pasteBoard setString:cell.textLabel.text];
}
}
参看。 关于OS13,shouldShowMenuForRowAt
和canPerformAction
作了解释,因此,你必须使用以下文本:
@available(iOS 13.0, *)
override func tableView(_ tableView: UITableView, contextMenuConfigurationForRowAt indexPath: IndexPath, point: CGPoint) -> UIContextMenuConfiguration? {
return UIContextMenuConfiguration(identifier: nil, previewProvider: nil, actionProvider: { suggestedActions in
return self.makeContextMenu(for: indexPath)
})
}
@available(iOS 13.0, *)
func makeContextMenu(for indexPath: IndexPath) -> UIMenu {
let copyAction = UIAction(title: "Copy") { [weak self] _ in
guard let self = self else { return }
let cell = self.tableView.cellForRow(at: indexPath)
let pasteboard = UIPasteboard.general
pasteboard.string = cell?.detailTextLabel?.text
}
// Create and return a UIMenu with the share action
return UIMenu(title: "Options", children: [copyAction])
}
<>说明: 最终结果将有所不同。 但是,这并不是 Apple果提供的箱子功能。 但是,对“环境”的检查是13Si >> General >> About。 长期压抑的囚室不会有下面的质子,而是老的质子。
《亚历山大法典》中有两种设想:
1. 如果你想要复制文本,不详细 文本:
//MARK: Delegate
func tableView(_ tableView: UITableView, shouldShowMenuForRowAt indexPath: IndexPath) -> Bool {
return (tableView.cellForRow(at: indexPath)?.textLabel?.text) != nil
}
func tableView(_ tableView: UITableView, canPerformAction action: Selector, forRowAt indexPath: IndexPath, withSender sender: Any?) -> Bool {
return action == #selector(copy(_:))
}
func tableView(_ tableView: UITableView, performAction action: Selector, forRowAt indexPath: IndexPath, withSender sender: Any?) {
if action == #selector(copy(_:)) {
let cell = tableView.cellForRow(at: indexPath)
let pasteboard = UIPasteboard.general
pasteboard.string = cell?.textLabel?.text
}
}
2. 您的习俗 标签和你想要复制所有习俗 标签案文 这是:
//MARK: Delegate
func tableView(_ tableView: UITableView, shouldShowMenuForRowAt indexPath: IndexPath) -> Bool {
return (tableView.cellForRow(at: indexPath) != nil)
}
func tableView(_ tableView: UITableView, canPerformAction action: Selector, forRowAt indexPath: IndexPath, withSender sender: Any?) -> Bool {
return action == #selector(copy(_:))
}
func tableView(_ tableView: UITableView, performAction action: Selector, forRowAt indexPath: IndexPath, withSender sender: Any?) {
if action == #selector(copy(_:)) {
/* change these array names according to your own array names */
let customlabel1 = customlabel1Array[indexPath.row]
let customlabel2 = customlabel2Array[indexPath.row]
let customlabel3 = customlabel3Array[indexPath.row]
let pasteboard = UIPasteboard.general
pasteboard.string = "(customlabel1)
(customlabel2)
(customlabel3)" /*
is for new line. */
}
}
}
您应如何安排您的席位。 自我考虑 • 从事这些工作的人:
override func viewDidLoad() {
yourTableView.delegate = self
}
For a basic app with nonconsumable in-app purchases, has anyone figured out best practices for using SKPaymentQueue s restoreCompletedTransactions? Observations I know it s recommended to always ...
I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...
I have a UITextField that is a subview of a UITableViewCell. When my view loads, I want the text field to become first responder. I have a pointer to the text field in the table cell, so to do this I ...
I ve been working on adding in-app purchases and was able to create and test in-app purchases using Store Kit (yay!). During testing, I exercised my app in a way which caused the app to crash mid ...
In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...
Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...
I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...
Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...