I have UITableView and each cell has button and text. Actual cell shouldn't be clickable, but button should. When I run in simulator I can hit button, but when deploy to device it is disabled. (edited)
Tried to follow many different steps to fix it from this post Button in UITableViewCell not responding under ios 7, such as ContentView.UserInteractionEnabled = False; for cell.
All of those for native iOS, maybe for Xamarin there are something else?
Any ideas what am I missing?
UITableViewCell code
this.DelayBind(() =>
{
var set = this.CreateBindingSet<CalendarCell, ActivityModel>();
set.Bind(CustomerNameLabel).To(a => a.Subject);
set.Bind(MarkAsMeetingButton).For(a => a.Hidden).WithConversion("ActivityTypeToVisibility");
set.Bind(MarkAsMeetingButton).To(a => a.SendMessageToViewModelCommand).CommandParameter(BindingContext);
set.Apply();
});
ContentView.UserInteractionEnabled = false;
UItableView code
public override void ViewDidLoad()
{
base.ViewDidLoad();
var source = new TableSource(CalendarList);
var set = this.CreateBindingSet<CalendarView, CalendarViewModel>();
set.Bind(source).To(vm => vm.CalendarList);
set.Apply();
CalendarList.Source = source;
CalendarList.ReloadData();
}
public class TableSource : MvxSimpleTableViewSource
{
private List<IGrouping<DateTime, ActivityModel>> GroupedCalendarList = new List<IGrouping<DateTime, ActivityModel>>();
public TableSource(UITableView calendarView) : base(calendarView, "CalendarCell", "CalendarCell")
{}
public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
{
var currentSection = GroupedCalendarList[indexPath.Section].ToList();
var item = currentSection[indexPath.Row];
var cell = GetOrCreateCellFor(tableView, indexPath, item);
var bindable = cell as IMvxDataConsumer;
if (bindable != null)
bindable.DataContext = item;
return cell;
}
public override nint RowsInSection(UITableView tableview, nint section)
{
return (nint)GroupedCalendarList[(int)section].Count();
}
public override UIView GetViewForHeader(UITableView tableView, nint section)
{
var label = new UILabel();
var currentDate = DateTime.Now;
var titleText = GroupedCalendarList[(int)section].FirstOrDefault().ScheduledStart.Value.Date;
return label;
}
public override nint NumberOfSections(UITableView tableView)
{
return (nint)GroupedCalendarList.Count;
}
public override void ReloadTableData()
{
if (ItemsSource == null) return;
var groupedCalendarList = (ItemsSource as List<ActivityModel>).GroupBy(cl => cl.ScheduledStart.Value.Date).ToList();
GroupedCalendarList = new List<IGrouping<DateTime, ActivityModel>>(groupedCalendarList);
base.ReloadTableData();
}
}
This code works absolutely fine for simulator, but doesn't work on device, UIButton in each cell is disabled.