【发布时间】:2013-12-16 01:14:49
【问题描述】:
我正在做一个涉及带有自定义单元格的 UITableView 的简单应用程序,我已阅读本教程 http://www.arcticmill.com/2012/05/uitableview-with-custom-uitableviewcell.html 一切都像一个魅力,但我不知道如何将 UITableView 添加到 UIView 或 UIScrollView 中,这样表格就不会占用所有屏幕。
using System;
using MonoTouch.UIKit;
using System.Collections.Generic;
using MonoTouch.Foundation;
using MonoTouch.ObjCRuntime;
namespace CustomUITableViewCellSample
{
public class ListSource : UITableViewSource
{
private List<string> _testData = new List<string> ();
public ListSource ()
{
_testData.Add ("Green");
_testData.Add ("Red");
_testData.Add ("Blue");
_testData.Add ("Yellow");
_testData.Add ("Purple");
_testData.Add ("Orange");
}
public override UITableViewCell GetCell (UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath)
{
// Reuse a cell if one exists
CustomListCell cell = tableView.DequeueReusableCell ("ColorCell") as CustomListCell;
if (cell == null) {
// We have to allocate a cell
var views = NSBundle.MainBundle.LoadNib ("CustomListCell", tableView, null);
cell = Runtime.GetNSObject (views.ValueAt (0)) as CustomListCell;
}
// This cell has been used before, so we need to update it's data
cell.UpdateWithData (_testData [indexPath.Row]);
return cell;
}
public override int RowsInSection (UITableView tableview, int section)
{
return _testData.Count;
}
}
}
如我所见,ListSource 继承自 UITableViewSource,但我真的不知道如何将它添加到另一个 ScrollView 中
【问题讨论】:
标签: c# ios uitableview xamarin.ios