ContentView中的button会导致MonoTouch运行时崩溃。 Monotouch 4.0中的错误?

我的应用程序在MT 3.0中运行良好。 现在当我升级。 当button位于ContentView中时,我看到错误。 单击button时发生崩溃。 码:

public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPa float width = tableView.Bounds.Width - 70; var cell = tableView.DequeueReusableCell(kCellIdentifier); //if (cell == null) //{ cell = new UITableViewCell(UITableViewCellStyle.Subtitle, kCellIdentifier); // } var behavior = tvc.behaviors.ElementAt(indexPath.Row); cell.TextLabel.Text = behavior.Name; cell.TextLabel.Font = UIFont.BoldSystemFontOfSize(22f); cell.DetailTextLabel.Text = behavior.Definition; var view = UIButton.FromType(UIButtonType.Custom); view.Tag = indexPath.Row; view.SetImage(UIImage.FromBundle("Images/plus.png"), UIControlState.Normal); view.Frame = new RectangleF(width - 50, 10, 50, 50); view.TouchUpInside += IncrementBehavior; var label = new UILabel(new RectangleF(width - 80, 10, 50, 50)); label.Text = behavior.CurrentCount.ToString(); label.BackgroundColor = UIColor.Clear; label.Font = UIFont.BoldSystemFontOfSize(24f); cell.ContentView.AddSubview(view); cell.ContentView.AddSubview(label); //cell.BackgroundColor = UIColor.Clear;) return cell; } void IncrementBehavior(object sender, EventArgs e) { var button = (UIButton)sender; var tag = button.Tag; var behavior = tvc.behaviors[tag]; var indexpath = NSIndexPath.FromRowSection(tag, 0); var newBehavior = Repository.GetBehavior(behavior.Id); newBehavior.CurrentCount++; Repository.Update(newBehavior); tvc.behaviors[tag] = newBehavior; tvc.TableView.ReloadRows(new[] { indexpath }, UITableViewRowAnimation.None); } 

我可以互换这些错误:

 Name: NSInvalidArgumentException Reason: -[__NSCFSet BridgeSelector]: unrecognized selector sent to instance 0x5c3c570 

 No constructor found for MonoTouch.UIKit.UIControlEventProxy::.ctor(System.IntPtr) 

不知道这是否是问题,但是当我升级到4.0时,我也有一些随机崩溃。 事实certificate,4.0 GC更具侵略性,而我以前逃避的东西不再是犹太教。

特别是,如果我有一个事件处理程序分配给一个button,我需要确保button被声明在课堂上。 如果它是在方法中声明的,那么GC将在引用超出范围时清除引用,然后当事件处理程序试图引发时,引用不再存在。

所以请尝试移动你的方法之外的button的声明。