C# 在不适合屏幕的单元格中设置后,值在不同的单元格中呈现
当我选择一个产品并将其添加到购物车时,用户可以转到购物车页面并编辑该产品 如果编辑为true,我将调用LoadValues并设置自定义产品 对于产品中的每个附加项,我创建一个ProductPropertiesCell,并为此附加项添加一个值。e、 g糖->无糖 ProductDetailsController.cs 调用LoadValues后的控制台输出 一, 二, 三, 四, 额外7 五, 额外10 对于每个单元格,我都会写入标记和添加到其中的值 ProductDetailsTableSource.cs 当单元格过多且不适合屏幕时,值将在不同的单元格中呈现 当所有的细胞都适合屏幕时,它的工作就完美了 当我的所有单元格都可以在屏幕上看到时,我的代码工作得非常完美。如果我在更大的模拟器上运行我的应用程序,屏幕上的所有单元格都是可见的,而无需滚动和工作 从这个现象来看,我猜您的问题不是像up代码那样重用表视图中的单元格C# 在不适合屏幕的单元格中设置后,值在不同的单元格中呈现,c#,ios,swift,xamarin,xamarin.ios,C#,Ios,Swift,Xamarin,Xamarin.ios,当我选择一个产品并将其添加到购物车时,用户可以转到购物车页面并编辑该产品 如果编辑为true,我将调用LoadValues并设置自定义产品 对于产品中的每个附加项,我创建一个ProductPropertiesCell,并为此附加项添加一个值。e、 g糖->无糖 ProductDetailsController.cs 调用LoadValues后的控制台输出 一, 二, 三, 四, 额外7 五, 额外10 对于每个单元格,我都会写入标记和添加到其中的值 ProductDetailsTableSour
public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
{
// Product Description
if (indexPath.Section == 0)
{
cellIdentifier = new NSString("descriptionCell");
var cell = tableView.DequeueReusableCell(cellIdentifier) as ProductDescriptionCell;
if (cell == null)
{
cell = new UITableViewCell (UITableViewCellStyle.Default, cellIdentifier);
// Here you can modify UITableViewCell to your custom cell
//cell = new ProductDescriptionCell(UITableViewCellStyle.Default, cellIdentifier)
}
cell.UpdateCell(SelectedProduct);
return cell;
}
// Properties or Product Type Cell
if (indexPath.Section <= SelectedProduct.Types.Count)
{
cellIdentifier = new NSString("propertiesCell");
var cell = tableView.DequeueReusableCell(cellIdentifier) as ProductPropertiesCell;
if (cell == null)
{
cell = new UITableViewCell (UITableViewCellStyle.Default, cellIdentifier);
// Here you can modify UITableViewCell to your custom cell
//cell = new ProductPropertiesCell(UITableViewCellStyle.Default, cellIdentifier)
}
cell.UpdatePicker (this, SelectedProduct.Types [indexPath.Section - SelectedProduct.Props.Count - 1], indexPath);
cell.Tag = indexPath.Section;
return cell;
}
// Comments
if (indexPath.Section == SelectedProduct.Types.Count + 1)
{
cellIdentifier = new NSString ("commentsCell");
var cell = tableView.DequeueReusableCell (cellIdentifier) as CommentsCell;
if (cell == null)
{
cell = new UITableViewCell (UITableViewCellStyle.Default, cellIdentifier);
// Here you can modify UITableViewCell to your custom cell
//cell = new CommentsCell(UITableViewCellStyle.Default, cellIdentifier)
}
cell.Setup (tableView, indexPath);
return cell;
}
// Quantity
else {
cellIdentifier = new NSString ("quantityCell");
var cell = tableView.DequeueReusableCell (cellIdentifier) as QuantityCell;
if (cell == null)
{
cell = new UITableViewCell (UITableViewCellStyle.Default, cellIdentifier);
// Here you can modify UITableViewCell to your custom cell
//cell = new QuantityCell(UITableViewCellStyle.Default, cellIdentifier)
}
cell.UpdateData (Parent);
return cell;
}
}
我删除
if (Edit) {
((ProductDetailsTableSource)ProductDetailsTable.Source).LoadValues (ProductDetailsTable);
}
和LoadValues方法
我直接将值更新到单元格,如下所示
// Properties or Product Type Cell
if (indexPath.Section <= SelectedProduct.Types.Count)
{
cellIdentifier = new NSString("propertiesCell");
var cell = tableView.DequeueReusableCell(cellIdentifier) as ProductPropertiesCell;
cell.UpdatePicker (this, SelectedProduct.Types [indexPath.Section - SelectedProduct.Props.Count - 1], indexPath);
//Edit mode -> add selected value
if (Parent.Edit)
cell.ValuePicked = Parent.Info.SavedProductInstace[indexPath.Section];
return cell;
}
现在它开始工作了 嗨,不太了解你的问题。当单元格太多且不适合屏幕时,值将呈现在不同的单元格中。@JuniorJiang MSFT Inside to LoadValues我获取每个单元格并添加一个值。只有标记为5的单元格具有值look my console output,但在具有小屏幕的emulator上,该值∑∑∑∧∧∧∧∏9、∑∑∑∑∑∧∧∧∧∧10被添加到标记为2的单元格中。标记为2的单元格必须为空,只有5必须具有值look EmulatorKey,感谢您的回复。您所说的应该显示在Tag5单元格上的内容,以及显示在Tag2单元格上的结果是什么意思?更新我的屏幕截图,请查看。谢谢你,明白了。滚动时应该重用单元格。每次变量单元格不为null//如果重用池中没有可用的单元格,iOS将自动创建一个//无需执行null检查并手动创建单元格var cell=MyCell tableView.DequeueReusableCell MyCellId,indexath;很好,很高兴您找到了解决方案:
if (cell == null)
{
cell = new UITableViewCell (UITableViewCellStyle.Default, cellIdentifier);
}
public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
{
// Product Description
if (indexPath.Section == 0)
{
cellIdentifier = new NSString("descriptionCell");
var cell = tableView.DequeueReusableCell(cellIdentifier) as ProductDescriptionCell;
if (cell == null)
{
cell = new UITableViewCell (UITableViewCellStyle.Default, cellIdentifier);
// Here you can modify UITableViewCell to your custom cell
//cell = new ProductDescriptionCell(UITableViewCellStyle.Default, cellIdentifier)
}
cell.UpdateCell(SelectedProduct);
return cell;
}
// Properties or Product Type Cell
if (indexPath.Section <= SelectedProduct.Types.Count)
{
cellIdentifier = new NSString("propertiesCell");
var cell = tableView.DequeueReusableCell(cellIdentifier) as ProductPropertiesCell;
if (cell == null)
{
cell = new UITableViewCell (UITableViewCellStyle.Default, cellIdentifier);
// Here you can modify UITableViewCell to your custom cell
//cell = new ProductPropertiesCell(UITableViewCellStyle.Default, cellIdentifier)
}
cell.UpdatePicker (this, SelectedProduct.Types [indexPath.Section - SelectedProduct.Props.Count - 1], indexPath);
cell.Tag = indexPath.Section;
return cell;
}
// Comments
if (indexPath.Section == SelectedProduct.Types.Count + 1)
{
cellIdentifier = new NSString ("commentsCell");
var cell = tableView.DequeueReusableCell (cellIdentifier) as CommentsCell;
if (cell == null)
{
cell = new UITableViewCell (UITableViewCellStyle.Default, cellIdentifier);
// Here you can modify UITableViewCell to your custom cell
//cell = new CommentsCell(UITableViewCellStyle.Default, cellIdentifier)
}
cell.Setup (tableView, indexPath);
return cell;
}
// Quantity
else {
cellIdentifier = new NSString ("quantityCell");
var cell = tableView.DequeueReusableCell (cellIdentifier) as QuantityCell;
if (cell == null)
{
cell = new UITableViewCell (UITableViewCellStyle.Default, cellIdentifier);
// Here you can modify UITableViewCell to your custom cell
//cell = new QuantityCell(UITableViewCellStyle.Default, cellIdentifier)
}
cell.UpdateData (Parent);
return cell;
}
}
if (Edit) {
((ProductDetailsTableSource)ProductDetailsTable.Source).LoadValues (ProductDetailsTable);
}
// Properties or Product Type Cell
if (indexPath.Section <= SelectedProduct.Types.Count)
{
cellIdentifier = new NSString("propertiesCell");
var cell = tableView.DequeueReusableCell(cellIdentifier) as ProductPropertiesCell;
cell.UpdatePicker (this, SelectedProduct.Types [indexPath.Section - SelectedProduct.Props.Count - 1], indexPath);
//Edit mode -> add selected value
if (Parent.Edit)
cell.ValuePicked = Parent.Info.SavedProductInstace[indexPath.Section];
return cell;
}