首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UITableViewRowAction手柄点击

UITableViewRowAction手柄点击
EN

Stack Overflow用户
提问于 2014-09-01 15:48:05
回答 1查看 1.8K关注 0票数 0

当我在表中的一行上滑动时,我使用UITableViewRowAction方法在iOS 8 Beta 2+中添加自定义按钮。我不知道如何处理点击事件,但它目前只是崩溃了我的应用程序。我尝试了以下几点:

代码语言:javascript
复制
public override UITableViewRowAction[] EditActionsForRow (UITableView tableView, NSIndexPath indexPath)
    {
        List<UITableViewRowAction> items = new List<UITableViewRowAction>();

        UITableViewRowAction button = new UITableViewRowAction ();
        button.Title="Test";
        button.BackgroundColor = UIColor.LightGray;
        button += delegate {   
            Console.WriteLine ("Hello World!");
        }; 

        items.Add(Button);

        return items.ToArray();
    }

但是,当我得到以下内容时,它将进行编译:

代码语言:javascript
复制
Operator '+=' cannot be applied to operands of type 'MonoTouch.UIKit.UITableViewRowAction' and 'anonymous method'.

如何分配处理程序来单击UITableViewRowAction?

EN

回答 1

Stack Overflow用户

发布于 2014-09-22 08:03:46

成功代码如下所示:

Swift

代码语言:javascript
复制
var button = UITableViewRowAction(style: UITableViewRowActionStyle.Default, title: "Test", handler:{ action, indexpath in println("Hello World!"); });

目标-c

代码语言:javascript
复制
UITableViewRowAction *button = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Test" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath)
{
    NSLog("Hello World!");
}];
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25609302

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档