在MonoTouch的填充一个简单的UITableView与UITableViewDataSource - 如何使用UITableViewDataSource [英] Populating a simple UITableView in MonoTouch with UITableViewDataSource - how to use UITableViewDataSource

查看:131
本文介绍了在MonoTouch的填充一个简单的UITableView与UITableViewDataSource - 如何使用UITableViewDataSource的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我爱MonoTouch的,到目前为止,但找到的文件,缺乏一旦你过去为数不多的初学者经验教训的样本。

I'm loving MonoTouch so far, but find the documentation and samples lacking once you get past the few beginner lessons.

我与填充在MonoTouch的一个简单的UITableView的一个简单的概念挣扎。我已经看到了定制单元这样做,并广泛地定制了不同的信息块列表的例子,但我只是在寻找如何实现这个简单的事情最低限度。我是一个专业的.NET开发人员,很新到iOS,所以还是我的包裹围绕它是如何工作的负责人。

I am struggling with a simple concept of populating a simple UITableView in MonoTouch. I have seen examples of doing this with custom cells, and extensively customizing the list with varying pieces of information, but I am just looking for the bare minimum of how to achieve this simple thing. I'm a professional .NET developer and very new to iOS, so still wrapping my head around how it works.

我只想以下。
创建的项
列表分配项所述的UITableView的该列表,以允许用户滚动列表。寻找一个非常非常简单的例子。

I just want the following. Create a list of items Assign that list of items to the UITableView to allow the user to scroll the list. Looking for a very very simple example.

我与正在创建一个UITableViewDataSource对象挣扎的最重要的事情。所以我不能创建它的实例,它是抽象的。我可以创建我自己的类继承它,但我希望在无需创建自己使用该框架的具体实现。我是太受.NET宠坏并创建一个新的类,或者它在某处框架存在,我只是无法找到它?

The biggest thing I am struggling with is creating a UITableViewDataSource object. It's abstract so I can't create an instance of it. I could create my own class that inherits it, but I am looking for a concrete implementation in the framework to use without having to create my own. Am I too spoiled by .NET and have to create a new class for it, or does it exist somewhere in the Framework and I just can't find it?

< STRONG>【答案在这里]
我找到了答案,但StackOverflow上不会让我回答我的问题与不足100声誉或除非我耐心等待8小时,这我不愿意做的事。以下答案:

[Answer here] I found an answer, but StackOverflow won't let me answer my own question with less than 100 reputation or unless I wait 8 hours which I am not willing to do. Answer below:

我创建了下面的类继承UITableViewSource。它是做这样的要求。 GetCell控制你将如何呈现在表格的单元格。

I created the following class that inherits UITableViewSource. It is a requirement to do it this way. GetCell controls how you will render the cell on the table.

创建了这样一个实例,并传递字符串来填充列表。

Create an instance of this and pass in a list of strings to populate.

这个例子来自(我修改了它略)这本书我从Wrox Press出版阅读 - 用MonoTouch的和.NET C#专业的iPhone编程

This example came from (I modified it slightly) the book I am reading from Wrox Press - "Professional iPhone Programming with MonoTouch and .NET C#"

public class TableViewSource : UITableViewSource
{
    private List<string> rows;

    public TableViewSource (List<string> list) 
    { 
            rows = list; 
    }

    public override int RowsInSection (UITableView tableview, int section) 
    { 
        return rows.Count; 
    }

    public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
    {  
        UITableViewCell cell = new UITableViewCell(UITableViewCellStyle.Default,"mycell"); 
        cell.TextLabel.Text = rows[indexPath.Row];
        return cell;
    } 
}



把你的屏幕上viewDidLoad中下面的代码。

Put the following code in ViewDidLoad on your screen.

var list = new List<String>()
{   
    "San Francisco",    
    "Buenos Aires", 
    "São Paulo"
};

TableViewSource tableData = new TableViewSource(list);
this.tblTrips.Source = tableData;

这给了我什么,我期待的,而无需深入了解MonoTouch.Dialog

This gives me what I am looking for without requiring a deep dive into MonoTouch.Dialog

推荐答案

的UITableView ,以及相关委托和数据源类型,是不是一个非常友好的API - 甚至更少为典型的.NET开发人员。有在需要时次,但在大多数情况下,你需要使用更简单的东西。

UITableView, and associated delegate and datasource types, is not a very friendly API - even less for the typical .NET developer. There are times when it's needed but, in most cases, you'll want to use something simpler.

创建列表项分配的项所述的UITableView的列表以允许用户滚动列表。寻找一个非常非常简单的例子。

Create a list of items Assign that list of items to the UITableView to allow the user to scroll the list. Looking for a very very simple example.

这似乎适合的 MonoTouch.Dialog 的目标。该组件现在随MonoTouch的,但你可以找到示例源代码在github上。

That seems to fit MonoTouch.Dialog's goal. The assembly is now shipped with MonoTouch but you can find the sample source code on github.

Xamarin的文档资料网站也有一个的教程 =http://g.xamarin.com/2012/02/10/easily-create-ios-user-interfaces-with- MonoTouch的-对话框/相对=nofollow>视频也是可用的。

Xamarin's documentation web site also has a tutorial for using MonoTouch.Dialog and a nice video is also available.

这篇关于在MonoTouch的填充一个简单的UITableView与UITableViewDataSource - 如何使用UITableViewDataSource的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆