zoukankan      html  css  js  c++  java
  • 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
    	}
    }
    

      运行结果:

  • 相关阅读:
    转载(SQL Server 存储过程的分页)
    学会了怎么样利用捕获异常提示数据库主键重复错误
    遇到.net加了验证控件的表单无法提交的问题
    过劳死IT界杀手 [注:该文属于转载,非原创],好可怕啊!
    很喜欢的一些道理。
    学会了在DropDownList的项里加多个空格
    好东东:asp.net利用多线程执行长时间的任务,客户端显示出任务的执行进度的示例
    javascript判断字符长度最好的方法
    layui中使用layverify进行非必填整数校验
    SuppressWarnings抑制警告的关键字
  • 原文地址:https://www.cnblogs.com/bubugao/p/4495458.html
Copyright © 2011-2022 走看看