新建一个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. Bootstrap 模态框(Modal)插件数据传值

    原文:http://blog.csdn.net/baalhuo/article/details/51178154 模态框具体代码如下: <!-- 模态框(Modal) --> <di ...

  2. vue2.0组件入门

    如何定义一个组件 在根目录src/components/文件夹下新建组件的文件夹Footer.vue组件 在Footer.vue中 <template> <div class=&qu ...

  3. 命令行参数解析函数 getopt

    命令行参数解析函数 —— getopt() getopt()函数声明如下: #include <unistd.h> int getopt(int argc, char * const ar ...

  4. php--转码函数

    最近在用dedecms二次开发会员功能:大家都知道dedecms编码是GBK格式的:所以在我们在项目中经常需要转码,在我了解中有两种转码方式:一是:iconv:二是mb_convert_encodin ...

  5. Android 防护扫盲篇

    一,已知防护策略 1.不可或缺的混淆 Java 是一种跨平台.解释型语言,Java 源代码编译成的class文件中有大量包含语义的变量名.方法名的信息,很容易被反编译为Java 源代码.为了防止这种现 ...

  6. JD路径配置及myeclipse主题和提示设置

    1. JDKAN安装及环境变量配置 安装jdk,注意记住安装路径(F:\Java\jdk1.8.0_121 )(个人爱好) 系统变量→新建 JAVA_HOME 变量 . 变量值填写jdk的安装目录(F ...

  7. fastjson的序列化属性

    在将使用JSON.toJSONString(result, SerializerFeature.PrettyFormat)将JSONObject转化为字符串时,可以指定一些序列化属性,设置转化后的字符 ...

  8. 346. Moving Average from Data Stream

    /* * 346. Moving Average from Data Stream * 2016-7-11 by Mingyang * 这里注意的就是(double) sum / count * su ...

  9. sed命令2

    测试文件sedtest.txt,内容为: [root@localhost sed]# cat sedtest.txt my cat's name is betty it's a cat; this i ...

  10. 【spring boot】注解@SpringBootApplication 相当于 @Configuration、@EnableAutoConfiguration 、 @ComponentScan 三个的作用

    注解@SpringBootApplication 相当于 @Configuration.@EnableAutoConfiguration . @ComponentScan 三个的作用 代码示例:Git ...