C# UITableView子类某些未被调用的重写方法
我已将UITableView子类化,子类中覆盖了填充表视图所需的方法。但是,虽然调用了C# UITableView子类某些未被调用的重写方法,c#,ios,uitableview,xamarin,C#,Ios,Uitableview,Xamarin,我已将UITableView子类化,子类中覆盖了填充表视图所需的方法。但是,虽然调用了NumberOfSections,但不调用numberofrowsinssection 下面的代码来自一个Xamarin项目,但这与它的等效本机版本没有什么不同,只是方法名称略有不同 partial class ShootsTable : UITableView, IUISearchResultsUpdating, IUISearchBarDelegate { public bool History {
NumberOfSections
,但不调用numberofrowsinssection
下面的代码来自一个Xamarin项目,但这与它的等效本机版本没有什么不同,只是方法名称略有不同
partial class ShootsTable : UITableView, IUISearchResultsUpdating, IUISearchBarDelegate
{
public bool History { get; set; }
public UIViewController Parent { get; set; }
private Bootleg.API.Event[] Events { get; set; }
private List<nint> ExpandedSections { get; }
public ShootsTable (IntPtr handle) : base (handle)
{
ExpandedSections = new List<nint> ();
SetEvents();
}
private void SetEvents()
{
if (History) {
Events = AppDelegate.Api.GetShootHistory ().ToArray();
} else {
Events = AppDelegate.Api.MyEvents.ToArray();
}
}
private void AddRefreshControl()
{
var refreshControl = new UIRefreshControl ();
refreshControl.AttributedTitle = new NSAttributedString ("Pull to refresh");
refreshControl.AddTarget (async delegate(object sender, EventArgs e) {
await AppDelegate.Api.RefreshEvents();
SetEvents();
ReloadData();
refreshControl.EndRefreshing();
}, UIControlEvent.ValueChanged);
AddSubview (refreshControl);
}
private void AddSearchControl()
{
var searchControl = new UISearchController (Parent);
searchControl.SearchResultsUpdater = this;
searchControl.SearchBar.Delegate = this;
TableHeaderView = searchControl.SearchBar;
}
public void UpdateSearchResultsForSearchController (UISearchController searchController)
{
SetEvents ();
Events = Events.Where (e => e.name.Contains (searchController.SearchBar.Text)).ToArray ();
ReloadData ();
}
public override nint NumberOfSections ()
{
if (Events != null && Events.Length > 0)
{
SeparatorStyle = UITableViewCellSeparatorStyle.SingleLine;
return Events.Length;
}
var label = new UILabel (new CGRect (Bounds.X, Bounds.Y, Bounds.Size.Width, Bounds.Size.Height));
label.Text = History ? "You have not contributed to any shoots yet." : "No shoots available.";
label.Lines = 2;
label.TextAlignment = UITextAlignment.Center;
BackgroundView = label;
SeparatorStyle = UITableViewCellSeparatorStyle.None;
return 0;
}
public override nint NumberOfRowsInSection (nint section)
{
var e = Events[section];
if (e.group == null)
{
return 1;
}
return ExpandedSections.Contains (section) ? e.events.Count : 0;
}
[Export ("tableView:heightForHeaderInSection:")]
public System.nfloat GetHeightForHeader (UIKit.UITableView tableView, System.nint section)
{
return Events [section].group == null ? 0 : tableView.SectionHeaderHeight;
}
[Export ("tableView:viewForHeaderInSection:")]
public UIKit.UIView GetViewForHeader (UIKit.UITableView tableView, System.nint section)
{
var e = Events [section];
if (e.group == null)
{
return null;
}
var cell = (ShootGroupCell) tableView.DequeueReusableCell (ShootGroupCell.Key);
cell.Event = e;
cell.AddGestureRecognizer (new UITapGestureRecognizer(() => {
if (ExpandedSections.Contains(section))
{
ExpandedSections.Remove(section);
tableView.ReloadSections(new NSIndexSet((nuint) section), UITableViewRowAnimation.Automatic);
} else {
ExpandedSections.Add(section);
tableView.ReloadSections(new NSIndexSet((nuint) section), UITableViewRowAnimation.Automatic);
}
}));
return cell.ContentView;
}
public override UITableViewCell CellAt (NSIndexPath ns)
{
var e = Events[ns.Section];
e = e.group == null ? e : e.events[ns.Row];
if (History) {
var cell = (ShootCell)DequeueReusableCell (ShootCell.Key);
cell.Event = e;
cell.Parent = Parent;
return cell;
} else {
var cell = (ShootJoinCell) DequeueReusableCell (ShootJoinCell.Key);
cell.Event = e;
return cell;
}
}
[Export ("tableView:heightForRowAtIndexPath:")]
public System.nfloat GetHeightForRow (UIKit.UITableView tableView, Foundation.NSIndexPath indexPath)
{
return Events [indexPath.Section].group == null || ExpandedSections.Contains (indexPath.Section) ? tableView.RowHeight : 0;
}
[Export ("tableView:didSelectRowAtIndexPath:")]
public async void RowSelected (UIKit.UITableView tableView, Foundation.NSIndexPath indexPath)
{
if (!History)
{
var e = Events [indexPath.Section];
if (e.group != null) {
e = e.events [indexPath.Row];
}
MBHUDView.HudWithBody ("Connecting Event...", MBAlertViewHUDType.ActivityIndicator, 0, true);
await AppDelegate.Api.ConnectToEvent (e, false);
MBHUDView.DismissCurrentHUD ();
if (AppDelegate.Api.CurrentEvent.id != e.id)
{
var alert = UIAlertController.Create ("Confirm", "This event requires you to confirm you wish to join.", UIAlertControllerStyle.Alert);
alert.AddAction(UIAlertAction.Create("Join", UIAlertActionStyle.Default, async delegate {
MBHUDView.HudWithBody ("Connecting Event...", MBAlertViewHUDType.ActivityIndicator, 0, true);
await AppDelegate.Api.ConnectToEvent (e, true);
MBHUDView.DismissCurrentHUD ();
e = AppDelegate.Api.CurrentEvent;
DialogHelper.PermissionsDialog (e, delegate {
Parent.PerformSegue("phasesSegue", tableView);
}, null, Parent);
}));
alert.AddAction(UIAlertAction.Create("Cancel", UIAlertActionStyle.Cancel, null));
Parent.PresentViewController (alert, true, null);
}
else
{
e = AppDelegate.Api.CurrentEvent;
DialogHelper.PermissionsDialog (e, delegate {
Parent.PerformSegue("phasesSegue", tableView);
}, null, Parent);
}
}
}
部分类ShootsTable:UITableView、IUISearchResultsUpdate、IUISearchBarDelegate
{
公共布尔历史记录{get;set;}
公共UIViewController父项{get;set;}
private Bootleg.API.Event[]事件{get;set;}
私有列表扩展节{get;}
公共ShootsTable(IntPtr句柄):基本(句柄)
{
ExpandedSections=新列表();
SetEvents();
}
私有void SetEvents()
{
国际单项体育联合会(历史){
Events=AppDelegate.Api.GetShootHistory().ToArray();
}否则{
Events=AppDelegate.Api.MyEvents.ToArray();
}
}
私有void AddRefreshControl()
{
var refreshControl=newuirefreshcontrol();
refreshControl.AttributedTitle=新的NSAttribute字符串(“拉入刷新”);
refreshControl.AddTarget(异步委托(对象发送方,事件参数e){
等待AppDelegate.Api.RefreshEvents();
SetEvents();
重新加载数据();
EndRefreshing();
},UIControlEvent.ValueChanged);
AddSubview(刷新控件);
}
私有void AddSearchControl()
{
var searchControl=新的UISearchController(父级);
searchControl.searchResultsUpdate=此;
searchControl.SearchBar.Delegate=此;
TableHeaderView=searchControl.SearchBar;
}
public void UpdateSearchResultsForSearchController(UISearchController searchController)
{
SetEvents();
Events=Events.Where(e=>e.name.Contains(searchController.SearchBar.Text)).ToArray();
重新加载数据();
}
公共覆盖Nin NumberOfSections()
{
if(Events!=null&&Events.Length>0)
{
SeparatorStyle=UITableViewCellSeparatorStyle.SingleLine;
返回事件。长度;
}
var label=新的UILabel(新的CGRect(Bounds.X,Bounds.Y,Bounds.Size.Width,Bounds.Size.Height));
label.Text=History?“您尚未参与任何快照。”:“没有可用的快照。”;
标签线=2;
label.TextAlignment=UITextAlignment.Center;
背景视图=标签;
SeparatorStyle=UITableViewCellSeparatorStyle.None;
返回0;
}
公共覆盖第九个数字行第九节(第九节)
{
var e=事件[部分];
如果(e.group==null)
{
返回1;
}
返回ExpandedSections.Contains(节)?e.events.Count:0;
}
[导出(“tableView:heightForHeaderInSection:”)]
public System.nfloat GetHeightForHeader(UIKit.UITableView tableView,System.nin节)
{
返回事件[section]。组==null?0:tableView.SectionHeaderHeight;
}
[导出(“tableView:ViewForHeaderSection:”)]
public UIKit.UIView GetViewForHeader(UIKit.UITableView tableView,System.nin节)
{
var e=事件[部分];
如果(e.group==null)
{
返回null;
}
var cell=(ShootGroupCell)tableView.DequeueReusableCell(ShootGroupCell.Key);
cell.Event=e;
cell.AddGestureRecognitizer(新的UITapGestureRecognitizer(()=>{
if(扩展节.包含(节))
{
展开部分。删除(部分);
tableView.ReloadSections(新的NSIndexSet((nuint)节),UITableViewRowAnimation.Automatic);
}否则{
扩展节。添加(节);
tableView.ReloadSections(新的NSIndexSet((nuint)节),UITableViewRowAnimation.Automatic);
}
}));
返回cell.ContentView;
}
公共覆盖UITableViewCell单元(NSINDENS)
{
var e=事件[ns.段];
e=e.group==null?e:e.events[ns.Row];
国际单项体育联合会(历史){
var cell=(ShootCell)DequeueReusableCell(ShootCell.Key);
cell.Event=e;
cell.Parent=Parent;
返回单元;
}否则{
var cell=(ShootJoinCell)DequeueReusableCell(ShootJoinCell.Key);
cell.Event=e;
返回单元;
}
}
[导出(“tableView:heightForRowAtIndexPath:”)]
公共System.nfloat GetHeightForRow(UIKIT.UITababVIEW TabLVIEW,基础.NSIXDEXPATH索引路径)
{
返回事件[indexPath.Section]。组==null | | ExpandedSections.Contains(indexPath.Section)?tableView.RowHeight:0;
}
[导出(“tableView:DidSelectRowatineXpath:”)]
公共异步空隙行选择(UIKIT.UITababVIEW TabLVIEW,基础.NSIXDEXPATH索引路径)
{
如果(!历史)
{
var e=事件[indexPath.Section];
如果(e.group!=null){
e=e.events[indexPath.Row];
}
mbhudwiew.HudWithBody(“连接事件…”,MBAlertViewHUDType.ActivityIndicator,0,true);
等待AppDelegate.Api.ConnectToEvent(e,false);
MBHUDView.DismissCurrentHUD();
if(AppDelegate.Api.CurrentEvent.id!=e.id)
{
var alert=UIAlertController.Create(“确认”,“此事件要求您确认您希望加入。”,UIAlertControllerStyle.alert);
AddAction(UIAlertAction.Create(“Join”),UIAlertActionStyle.Default,异步委托{
mbhudwiew.HudWithBody(“连接事件…”,MBAlertViewHUDType.ActivityIndicator,0,true);
等待AppDelegate.Api.ConnectToEvent(e,true);
MBHUDView.DismissCurrentHUD();