簡體   English   中英

如何使用Xamarin IOS在UITableView中顯示多個列?

[英]How to display multiple columns in a UITableView using Xamarin IOS?

我試圖使用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樣式等)。

每個蘋果:

集合視圖提供與表視圖相同的常規功能,除了集合視圖不僅可以支持單列布局,還可以支持更多的功能

參考: UICollectionView

Xamarin在使用集合視圖方面有一篇很棒的技術文章:

在此處輸入圖片說明 集合視圖簡介

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM