Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用Xamarin IOS在UITableView中显示多列?_C#_Ios_Xamarin_Xamarin.ios - Fatal编程技术网

C# 如何使用Xamarin IOS在UITableView中显示多列?

C# 如何使用Xamarin IOS在UITableView中显示多列?,c#,ios,xamarin,xamarin.ios,C#,Ios,Xamarin,Xamarin.ios,我试图使用Xamarin IOS在表视图中显示多个表单元格,但它总是在表行中显示一个单元格,而不是两个单元格。 请参考下面的图片以了解更多信息 请查找下面的代码 //Table Cell Code public class GridItemCell : UITableViewCell { public static readonly string ID = "MultiColumnCell"; NSString cellIdentifier; bool status;

我试图使用Xamarin IOS在表视图中显示多个表单元格,但它总是在表行中显示一个单元格,而不是两个单元格。 请参考下面的图片以了解更多信息

请查找下面的代码

//Table Cell Code

public class GridItemCell : UITableViewCell
{
    public static readonly string ID = "MultiColumnCell";
    NSString cellIdentifier;
    bool status;

    public UILabel LeftValue { get; set; }
    public UILabel RightValue { get; set; }

    public GridItemCell()
    {
        LeftValue = new UILabel(new RectangleF(0, 5, 15, 50));
        RightValue = new UILabel(new RectangleF(15, 5, 15, 50));
        LeftValue.BackgroundColor = UIColor.Red;
        RightValue.BackgroundColor = UIColor.Green;

        AddSubview(LeftValue);
        AddSubview(RightValue);
    }
}  

//Table Source
public class GridItemSource : UITableViewSource
{
    public virtual nint NumberOfRowsInSections(UITableView tableView)
    {
        return 2;
    }

    public override nint RowsInSection(UITableView tableview, nint section)
    {
        return 5;
    }

    public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
    {
        var cell = tableView.DequeueReusableCell(GridItemCell.ID) as GridItemCell;
        if(cell == null)
        {
            cell = new GridItemCell();
        }
        cell.LeftValue.Text = "Left " + indexPath.Row;
        cell.RightValue.Text = "Right " + indexPath.Row;
        return cell;
    }
}  

//View Controller Code

UITableView _tableView = new UITableView
        {
            Frame = new CoreGraphics.CGRect(0, 60, UIScreen.MainScreen.Bounds.Width, UIScreen.MainScreen.Bounds.Height - 26),
            Source = new ProductItemsSource(data,strCategoryViewType,this),
            AlwaysBounceVertical = false
        };
通过使用这段代码,我得到了一个单元格的表视图。但是我需要两个不同的单元格在一行中进行单元格选择。
有人能帮我解决这个问题吗。

您需要使用
UICollectionView
而不是
UITableView
来实现所需功能

表视图通常基于每行一个数据集,您可以返回两组图像/项目/价格的集合,您的单元格实际上会同时显示两组数据,但这确实打破了表视图的使用设计(自动缓存、iOS UI样式等)

每个苹果: 集合视图提供与表视图相同的常规功能,不同之处在于集合视图支持的不仅仅是单列布局

参考:

Xamarin有一篇关于使用集合视图的优秀科技文章:


我认为UICollectionView更适合这种情况。UITableView显示每行一个单元格,您可以创建一个包含两个项目的单元格,以实现您的目标。Thank you@PilatusThank you@SushiHangover。我将使用UICollectionView来完成我的任务。@没问题,一旦您切换到
UICollectionView
,如果您有任何问题,请发布新问题,在此之前,干杯