【发布时间】:2013-01-07 18:19:26
【问题描述】:
在我用于 iPhone 的 Monotouch 应用程序中,我尝试将分段控制器添加到 UITableViewCell 以作为每行中值的切换。一切都正确显示,单击时第一行最初将正常工作。但是,在该行离开屏幕并重新加载后,如果我再次单击分段控制器,我会收到异常:
由于未处理的异常而终止运行时 [错误] 致命的未处理异常:System.Exception:在已被 GC 处理的 MonoTouch.UIKit.UIControlEventProxy (0x16D793C0) 类型的托管对象上从 Objective-c 调用选择器 ---> System.MissingMethodException:未找到 MonoTouch 的构造函数.UIKit.UIControlEventProxy::.ctor(System.IntPtr)
我听说过使用 Monotouch 的人尝试将按钮放在表格单元格中的类似问题。一般建议是将每个表格单元格添加到列表中以防止其被垃圾收集,但这对我不起作用。
有解决这个问题的办法吗?
这是我的 GetCell 代码的简化版本:
public override UITableViewCell GetCell (UITableView tableView, NSIndexPath indexPath)
{
Hashtable rowData = dataList [indexPath.Row];
FilterListToggleCell cell;
cell = (FilterListToggleCell)tableView.DequeueReusableCell ("FilterTogglePlusCell");
cacheList.Add(cell.Toggle);//cache only the segcontrol
//cacheList.Add(cell);//also previously tried caching the whole cell
cell.Title.Text = (string)rowData["title"];
if(additionalFields.Contains((string)rowData["key"])){
cell.Toggle.SelectedSegment = 0;
} else {
cell.Toggle.SelectedSegment = 1;
}
cell.Toggle.ValueChanged += (sender, e) => {
UISegmentedControl toggle = (UISegmentedControl)sender;
if(toggle.SelectedSegment == 0){
Console.WriteLine("Toggle YES");
} else {
Console.WriteLine("Toggle NO");
}
};
cell.Toggle.Tag = indexPath.Row;
return cell;
}
【问题讨论】:
标签: uitableview xamarin.ios sigabrt