是否可以刷新或重绘UICollectionView中的补充视图?我有一个场景,其中我将使用行的插入/删除来更新每个节,在此情况下,我需要更新节标题或所谓的补充视图(它具有UI元素,其可见性取决于项数)在该部分)。那么,有什么方法可以更新UICollectionView的补充视图,而无需更新其他任何内容?
另外,如果特定部分不包含任何数据,我需要将补充视图的大小设置为空吗?
补充意见:
using System;
using System.Collections.Generic;
using Foundation;
using IpcCommon;
using IpcCommon.Enumerations;
using IpcCommon.Model;
using ObjCRuntime;
using UIKit;
namespace ipc_offline_app.iOS.Portal.CustomCells.Dashboard.Redesign
{
public partial class DashboardHeader : UICollectionReusableView
{
public static readonly NSString Key = new NSString("DashboardHeader");
public static readonly UINib Nib;
private DashCategories _dashboardCategory;
private bool _hideViewAll;
private IShelfItemClickListener _listener;
private string _title;
static DashboardHeader()
{
Nib = UINib.FromName("DashboardHeader", NSBundle.MainBundle);
}
protected DashboardHeader(IntPtr handle) : base(handle)
{
// Note: this .ctor should not contain any initialization logic.
}
public static DashboardHeader CreateCell()
{
var array = NSBundle.MainBundle.LoadNib("DashboardHeader", null, null);
var cell = Runtime.GetNSObject<DashboardHeader>(array.ValueAt(0));
return cell;
}
public void PopulateCell(string title, IShelfItemClickListener listener, bool hideViewAll, DashCategories category = DashCategories.NONE)
{
_title = title;
_dashboardCategory = category;
_listener = listener;
ViewAllButton.Hidden = hideViewAll;
_hideViewAll = hideViewAll;
TitleButton.SetTitle(_title, UIControlState.Normal);
UpdateViewAllVisibility();
}
[Export("awakeFromNib")]
public new void AwakeFromNib()
{
ViewAllButton.Layer.CornerRadius = 5;
ViewAllButton.Layer.BorderWidth = 1;
ViewAllButton.Layer.BorderColor = Utils.ColorFromHex(Colors.SILVER).CGColor;
}
partial void OpenSection(NSObject sender)
{
if (_listener != null && _dashboardCategory != DashCategories.NONE)
_listener.OnShelfItemClicked(_dashboardCategory, IpcCommon.Constants.VIEW_TYPE_GALLERY);
}
public void UpdateViewAllVisibility(Dictionary<DashCategories, List<Assignment>> filteredAssignments = null)
{
if (filteredAssignments != null && filteredAssignments[_dashboardCategory].Count > IpcCommon.Constants.MAX_SECTION_ITEMS)
_hideViewAll = false;
ViewAllButton.Hidden = _hideViewAll;
NSLayoutConstraint trailingConstraint;
if (_hideViewAll)
trailingConstraint = NSLayoutConstraint.Create(TitleButton, NSLayoutAttribute.Trailing, NSLayoutRelation.Equal, ViewAllButton, NSLayoutAttribute.Trailing, 1, 0);
else
trailingConstraint = NSLayoutConstraint.Create(TitleButton, NSLayoutAttribute.Trailing, NSLayoutRelation.Equal, ViewAllButton, NSLayoutAttribute.Leading, 1, -10);
AddConstraint(trailingConstraint);
LayoutIfNeeded();
LayoutSubviews();
}
}
}
最佳答案
解:
您可以获取对插入/删除数据的该部分的每个可见补充视图的引用。
我看不到您的代码,您应该知道要插入/删除数据的indexPath
的section
。
例如:
// indexP here is an example
NSIndexPath indexP = NSIndexPath.FromRowSection(0,0);
Header supplementaryView = CollectionView.GetSupplementaryView(myelementkind, indexP) as Header;
//perform your own action here
supplementaryView.checkvisibility();