当我在表中的一行上滑动时,我使用UITableViewRowAction方法在iOS 8 Beta 2+中添加自定义按钮。我不知道如何处理点击事件,但它目前只是崩溃了我的应用程序。我尝试了以下几点:
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();
}但是,当我得到以下内容时,它将进行编译:
Operator '+=' cannot be applied to operands of type 'MonoTouch.UIKit.UITableViewRowAction' and 'anonymous method'.如何分配处理程序来单击UITableViewRowAction?
发布于 2014-09-22 08:03:46
成功代码如下所示:
Swift
var button = UITableViewRowAction(style: UITableViewRowActionStyle.Default, title: "Test", handler:{ action, indexpath in println("Hello World!"); });目标-c
UITableViewRowAction *button = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Test" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath)
{
NSLog("Hello World!");
}];https://stackoverflow.com/questions/25609302
复制相似问题