新建一个Single View Application

添加一个空类如下:

using System;
using UIKit;
using Foundation; namespace BasicTable
{
public class TableSource : UITableViewSource
{
string[] TableItems;
string cellIdentifier="TableCell";
public TableSource (string[] items)
{
TableItems = items;
}
public override nint RowsInSection (UITableView tableview, nint section)
{
return TableItems.Length;
} public override UITableViewCell GetCell (UITableView tableView, NSIndexPath indexPath)
{
UITableViewCell cell = tableView.DequeueReusableCell (cellIdentifier);
if (cell == null) {
cell = new UITableViewCell (UITableViewCellStyle.Default,cellIdentifier);
cell.TextLabel.Text=TableItems[indexPath.Row]; }
return cell;
}
public override void RowSelected (UITableView tableView, NSIndexPath indexPath)
{
new UIAlertView ("Row Selected", TableItems [indexPath.Row], null, "OK", null).Show ();
tableView.DeselectRow (indexPath,true);
}
}
}

  控制器中的代码如下:

using System;
using System.Drawing; using Foundation;
using UIKit; namespace BasicTable
{
public partial class BasicTableViewController : UIViewController
{
public BasicTableViewController (IntPtr handle) : base (handle)
{
} public override void DidReceiveMemoryWarning ()
{
// Releases the view if it doesn't have a superview.
base.DidReceiveMemoryWarning (); // Release any cached data, images, etc that aren't in use.
} #region View lifecycle public override void ViewDidLoad ()
{
base.ViewDidLoad (); // Perform any additional setup after loading the view, typically from a nib.
UITableView table=new UITableView(View.Bounds);
string[] tableItems = new string[]{ "Vegetables","Fruits","Flower Buds","Legumes","Bulbs","Tubers","Bok choy",
"Cabbage","Celery","Dandelion","Epazote","Endive","Fiddlehead","Fluted pumpkin","Garden Rocket",
"Good King Henry","Kai-lan","Komatsuna","Lamb's lettuce","Land cress","Melokhia",
"Mustard","Napa cabbage","New Zealand Spinach","Orache","Pak choy","Paracress","Radicchio","Sea beet","Tatsoi"};
table.Source = new TableSource (tableItems);
Add (table);
} public override void ViewWillAppear (bool animated)
{
base.ViewWillAppear (animated);
} public override void ViewDidAppear (bool animated)
{
base.ViewDidAppear (animated);
} public override void ViewWillDisappear (bool animated)
{
base.ViewWillDisappear (animated);
} public override void ViewDidDisappear (bool animated)
{
base.ViewDidDisappear (animated);
} #endregion
}
}

  运行结果:

UITableView基础入门的更多相关文章

  1. Swift语法基础入门四(构造函数, 懒加载)

    Swift语法基础入门四(构造函数, 懒加载) 存储属性 具备存储功能, 和OC中普通属性一样 // Swfit要求我们在创建对象时必须给所有的属性初始化 // 如果没办法保证在构造方法中初始化属性, ...

  2. js学习笔记:webpack基础入门(一)

    之前听说过webpack,今天想正式的接触一下,先跟着webpack的官方用户指南走: 在这里有: 如何安装webpack 如何使用webpack 如何使用loader 如何使用webpack的开发者 ...

  3. 「译」JUnit 5 系列:基础入门

    原文地址:http://blog.codefx.org/libraries/junit-5-basics/ 原文日期:25, Feb, 2016 译文首发:Linesh 的博客:JUnit 5 系列: ...

  4. .NET正则表达式基础入门

    这是我第一次写的博客,个人觉得十分不容易.以前看别人写的博客文字十分流畅,到自己来写却发现十分困难,还是感谢那些为技术而奉献自己力量的人吧. 本教程编写之前,博主阅读了<正则指引>这本入门 ...

  5. 从零3D基础入门XNA 4.0(2)——模型和BasicEffect

    [题外话] 上一篇文章介绍了3D开发基础与XNA开发程序的整体结构,以及使用Model类的Draw方法将模型绘制到屏幕上.本文接着上一篇文章继续,介绍XNA中模型的结构.BasicEffect的使用以 ...

  6. 从零3D基础入门XNA 4.0(1)——3D开发基础

    [题外话] 最近要做一个3D动画演示的程序,由于比较熟悉C#语言,再加上XNA对模型的支持比较好,故选择了XNA平台.不过从网上找到很多XNA的入门文章,发现大都需要一些3D基础,而我之前并没有接触过 ...

  7. Shell编程菜鸟基础入门笔记

    Shell编程基础入门     1.shell格式:例 shell脚本开发习惯 1.指定解释器 #!/bin/bash 2.脚本开头加版权等信息如:#DATE:时间,#author(作者)#mail: ...

  8. [Spring框架]Spring AOP基础入门总结二:Spring基于AspectJ的AOP的开发.

    前言: 在上一篇中: [Spring框架]Spring AOP基础入门总结一. 中 我们已经知道了一个Spring AOP程序是如何开发的, 在这里呢我们将基于AspectJ来进行AOP 的总结和学习 ...

  9. [Spring框架]Spring AOP基础入门总结一.

    前言:前面已经有两篇文章讲了Spring IOC/DI 以及 使用xml和注解两种方法开发的案例, 下面就来梳理一下Spring的另一核心AOP. 一, 什么是AOP 在软件业,AOP为Aspect ...

随机推荐

  1. 实验六 TLS协议报文解析

    一.实验目的 1.访问一个https://....的网站,捕TLS包并分析报文序列. 2.分析连接建立的完整过程,如:TCP三次握手.SSL安全连接,使用TLS协议连接.协商过程,加密传送的状态.TC ...

  2. CodeForces 97D. Robot in Basement

    time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standa ...

  3. 【NOIP2016练习】T2 旅行(树形DP,换根)

    题意:小C上周末和他可爱的同学小A一起去X湖玩. X湖景区一共有n个景点,这些景点由n-1条观光道连接着,从每个景点开始都可以通过观光道直接或间接地走到其他所有的景点.小C带着小A从1号景点开始游玩. ...

  4. Why do I keep getting mixed tabs and spaces in a Visual Studio C# code window?[vs power tools issue transfered]

    goto tools->option->power tools-> turn "use mixed tabs" option to off. you won`t ...

  5. Android 中图可以用到的图片处理类 BitmapUtils

    Android在实际开发中很多时候都要对图片进行一定的处理,这里总结的BitmapUtils 类包括一下几个功能: 1.Android图片倒影, 2.Android图片模糊处理, 3.Android图 ...

  6. mysql数据库编码格式

    1.查看数据库编码格式 mysql> show variables like 'character_set_database'; 2.查看数据表的编码格式 mysql> show crea ...

  7. mysql 新增用户并授权

    grant all privileges on *.* to 'root'@‘%’ identified by '123456'; *.* 表示所有资源. 刷新权限 flush privileges;

  8. hdu 4514(树的直径+并查集)

    湫湫系列故事——设计风景线 Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Tot ...

  9. 设计模式原来如此-单例模式(Singleton Pattern)

    简单介绍一下我对Singleton的理解,说的不好请大家多多指点. 单例模式的简单定义就是确保一个类只有一个实例,并提供一个全局访问点. 单例模式有哪些用处呢? 有一些对象其实我们只需要一个,比方说: ...

  10. (6)C#事务处理

    为了方便移到了ADO.NET分类里 事务的主要特征是,任务要么全部完成,要么都不完成 事务常用于写入或更新数据库中的数据.将数据写入文件或注册表也可以使用事物. ADO.NET不支持跨越多个连接的事物 ...