【发布时间】:2019-03-10 19:27:12
【问题描述】:
是否可以只刷新或重绘 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();
}
}
}
【问题讨论】:
-
有没有类似 CollectionView.ReloadItems 用于重新加载补充视图?
标签: ios xamarin.ios uicollectionview