UITableView基础入门
新建一个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基础入门的更多相关文章
- Swift语法基础入门四(构造函数, 懒加载)
Swift语法基础入门四(构造函数, 懒加载) 存储属性 具备存储功能, 和OC中普通属性一样 // Swfit要求我们在创建对象时必须给所有的属性初始化 // 如果没办法保证在构造方法中初始化属性, ...
- js学习笔记:webpack基础入门(一)
之前听说过webpack,今天想正式的接触一下,先跟着webpack的官方用户指南走: 在这里有: 如何安装webpack 如何使用webpack 如何使用loader 如何使用webpack的开发者 ...
- 「译」JUnit 5 系列:基础入门
原文地址:http://blog.codefx.org/libraries/junit-5-basics/ 原文日期:25, Feb, 2016 译文首发:Linesh 的博客:JUnit 5 系列: ...
- .NET正则表达式基础入门
这是我第一次写的博客,个人觉得十分不容易.以前看别人写的博客文字十分流畅,到自己来写却发现十分困难,还是感谢那些为技术而奉献自己力量的人吧. 本教程编写之前,博主阅读了<正则指引>这本入门 ...
- 从零3D基础入门XNA 4.0(2)——模型和BasicEffect
[题外话] 上一篇文章介绍了3D开发基础与XNA开发程序的整体结构,以及使用Model类的Draw方法将模型绘制到屏幕上.本文接着上一篇文章继续,介绍XNA中模型的结构.BasicEffect的使用以 ...
- 从零3D基础入门XNA 4.0(1)——3D开发基础
[题外话] 最近要做一个3D动画演示的程序,由于比较熟悉C#语言,再加上XNA对模型的支持比较好,故选择了XNA平台.不过从网上找到很多XNA的入门文章,发现大都需要一些3D基础,而我之前并没有接触过 ...
- Shell编程菜鸟基础入门笔记
Shell编程基础入门 1.shell格式:例 shell脚本开发习惯 1.指定解释器 #!/bin/bash 2.脚本开头加版权等信息如:#DATE:时间,#author(作者)#mail: ...
- [Spring框架]Spring AOP基础入门总结二:Spring基于AspectJ的AOP的开发.
前言: 在上一篇中: [Spring框架]Spring AOP基础入门总结一. 中 我们已经知道了一个Spring AOP程序是如何开发的, 在这里呢我们将基于AspectJ来进行AOP 的总结和学习 ...
- [Spring框架]Spring AOP基础入门总结一.
前言:前面已经有两篇文章讲了Spring IOC/DI 以及 使用xml和注解两种方法开发的案例, 下面就来梳理一下Spring的另一核心AOP. 一, 什么是AOP 在软件业,AOP为Aspect ...
随机推荐
- [暑假集训--数位dp]hdu3709 Balanced Number
A balanced number is a non-negative integer that can be balanced if a pivot is placed at some digit. ...
- Mondriaan's Dream(poj 2411)
题意:在n*m的方格里铺1*2的骨牌,有多少种方案 /* 第一次做插头DP,感觉和状压差不多. 这道题是利用上一行的状态来更新下一行的状态. 1代表上一行这个位置填了一个竖的(即本行可以填): 0代表 ...
- C语言指针与数组
C语言指针与数组 数组的下标应该从0还是1开始? 我提议的妥协方案是0.5,可惜他们未予认真考虑便一口回绝 -- Stan Kelly-Bootle 1. 数组并非指针 为什么很多人会认为指 ...
- TroubleShoot:The context has expired (0×80090317)
网上搜了一下,服务器上的时间不正确,在SharePoint 设置中,可以通过管理中心设置下Time Zone 和服务器的时间上一致.
- loading上下左右居中
.loading { width: 50px; height: 60px; text-align: center; font-size: 10px; position:fixed; left:50%; ...
- mysql中的SQL_CACHE(性能更优化)
mysql中的sql_cache是个容易忽视的地方,要 使用的话,必须先设置query_cache_size, 以及设置query_cache_type ,其中 query_cache_type 这个 ...
- Codeforces Round #482 (Div. 2)
D. Kuro and GCD and XOR and SUM 字典树真好玩... 牛老板提供的思路:建1e5个 字典树,每个数插入到以它的因子为根所在的字典树中,这样就实现了整除,当然gcd(k, ...
- spring mvc构建WEB应用程序入门例子
在使用spring mvc 构建web应用程序之前,需要了解spring mvc 的请求过程是怎样的,然后记录下如何搭建一个超简单的spring mvc例子. 1) spring mvc的请求经历 请 ...
- PyTorch学习笔记之DataLoaders
A DataLoader wraps a Dataset and provides minibatching, shuffling, multithreading, for you. import t ...
- mysql存储过程命令行批量插入N条数据命令
原文:http://blog.csdn.net/tomcat_2014/article/details/53377924 delimiter $$ create procedure myproc () ...