许可优化
许可优化
产品
产品
解决方案
解决方案
服务支持
服务支持
关于
关于
软件库
当前位置:服务支持 >  软件文章 >  UITableView基础入门:iOS UITableView基础教程:从零开始

UITableView基础入门:iOS UITableView基础教程:从零开始

阅读数 5
点赞 0
article_banner

新建一个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	}}

  运行结果:

转载于:https://www.cnblogs.com/bubugao/p/4495458.html


免责声明:本文系网络转载或改编,未找到原创作者,版权归原作者所有。如涉及版权,请联系删


相关文章
技术文档
QR Code
微信扫一扫,欢迎咨询~
customer

online

联系我们
武汉格发信息技术有限公司
湖北省武汉市经开区科技园西路6号103孵化器
电话:155-2731-8020 座机:027-59821821
邮件:tanzw@gofarlic.com
Copyright © 2023 Gofarsoft Co.,Ltd. 保留所有权利
遇到许可问题?该如何解决!?
评估许可证实际采购量? 
不清楚软件许可证使用数据? 
收到软件厂商律师函!?  
想要少购买点许可证,节省费用? 
收到软件厂商侵权通告!?  
有正版license,但许可证不够用,需要新购? 
联系方式 board-phone 155-2731-8020
close1
预留信息,一起解决您的问题
* 姓名:
* 手机:

* 公司名称:

姓名不为空

姓名不为空

姓名不为空
手机不正确

手机不正确

手机不正确
公司不为空

公司不为空

公司不为空