简化MonoTouch.Dialog的使用
读了一位园友写的使用MonoTouch.Dialog简化iOS界面开发,我来做个补充;
相信使用过DialogViewController(以下简称DVC)的同学都知道它的强大,但是缺点也是明显的,应付不来复杂的UI布局;
因为DVC的View就是一个UITableView;有的时候不得不放弃DVC来满足复杂UI的要求;
但是用过了DVC后,回过头来使用原生的UITableView是一件很痛苦的事;
我们想要的只是UITableView能够基于RootElement的来进行UI构造,所以只要把这部分功能从DVC择出来就行了。
首先从UITableView派生TableView
public class TableView : UITableView
{
private RootElement root;
public RootElement Root
{
get
{
return root;
}
set
{
if (root == value)
return;
root = value;
root.TableView = this;
root.Prepare();
Source = root.UnevenRows ? new SizingSource(root) : new Source(root);
}
} public TableView()
{
InitializeComponent();
} public TableView(UITableViewStyle style)
: base(RectangleF.Empty, style)
{
InitializeComponent();
} protected virtual void InitializeComponent()
{
//InitializeComponent
}
}
然后从UITableViewSource派生Source
public class Source : UITableViewSource
{
protected RootElement Root; public Source(RootElement root)
{
Root = root;
} public override Int32 RowsInSection(UITableView tableview, Int32 section)
{
return Root[section].Elements.Count;
} public override Int32 NumberOfSections(UITableView tableView)
{
return Root.Count;
} public override String TitleForHeader(UITableView tableView, Int32 section)
{
return Root[section].Caption;
} public override String TitleForFooter(UITableView tableView, Int32 section)
{
return Root[section].Footer;
} public override UITableViewCell GetCell(UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath)
{
var section = Root[indexPath.Section];
var element = section.Elements[indexPath.Row]; return element.GetCell(tableView);
} public override void WillDisplay(UITableView tableView, UITableViewCell cell, NSIndexPath indexPath)
{
if (Root.NeedColorUpdate)
{
var section = Root[indexPath.Section];
var element = section.Elements[indexPath.Row];
var colorized = element as MonoTouch.Dialog.IColorizeBackground;
if (colorized != null)
colorized.WillDisplay(tableView, cell, indexPath);
}
} public override void RowDeselected(UITableView tableView, NSIndexPath indexPath)
{
var section = Root[indexPath.Section];
var element = section.Elements[indexPath.Row]; element.Deselected(null, tableView, indexPath);
} public override void RowSelected(UITableView tableView, NSIndexPath indexPath)
{
var section = Root[indexPath.Section];
var element = section.Elements[indexPath.Row]; element.Selected(null, tableView, indexPath);
} public override UIView GetViewForHeader(UITableView tableView, Int32 sectionIdx)
{
var section = Root[sectionIdx];
return section.HeaderView;
} public override Single GetHeightForHeader(UITableView tableView, Int32 sectionIdx)
{
var result = 0.001f;//本来应该是0,但是在ios7或以上版本在tableview的头部和底部或出现大约44px的空白。未解之谜!!!
var section = Root[sectionIdx];
if (!String.IsNullOrEmpty(section.Caption) || !String.IsNullOrEmpty(section.Header))
result = 30f;
if (section.HeaderView != null)
result = section.HeaderView.Frame.Height; return result;
} public override UIView GetViewForFooter(UITableView tableView, Int32 sectionIdx)
{
var section = Root[sectionIdx];
return section.FooterView;
} public override float GetHeightForFooter(UITableView tableView, Int32 sectionIdx)
{
var result = 0.001f;//本来应该是0,但是在ios7或以上版本在tableview的头部和底部或出现大约44px的空白。未解之谜!!!
var section = Root[sectionIdx];
if (!String.IsNullOrEmpty(section.Footer))
result = 30f;
if (section.FooterView != null)
result = section.HeaderView.Frame.Height;
return result;
}
}
最后从Source派生SizingSource
public class SizingSource : Source
{
public SizingSource(RootElement root) : base(root) { } public override float GetHeightForRow(UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath)
{
var section = Root[indexPath.Section];
var element = section.Elements[indexPath.Row]; var sizable = element as MonoTouch.Dialog.IElementSizing;
if (sizable == null)
return tableView.RowHeight;
return sizable.GetHeight(tableView, indexPath);
}
}
用了觉得好,请点个赞。
简化MonoTouch.Dialog的使用的更多相关文章
- 使用MonoTouch.Dialog简化iOS界面开发
MonoTouch.Dialog简称MT.D,是Xamarin.iOS的一个RAD工具包.它提供易于使用的声明式API,不需要使用导航控制器.表格等ViewController来定义复杂的应用程序UI ...
- MonoTouch.Dialog简介
新建一个Single View Application项目 添加程序集 MonoTouch.Dialog.dll引用 删除 MainStoryboard.storyboard 添加空类Task.cs ...
- 【Xamarin挖墙脚系列:Mono项目的图标为啥叫Mono】
因为发起人大Boss :Miguel de lcaza 是西班牙人,喜欢猴子.................就跟Hadoop的创始人的闺女喜欢大象一样...................... 历 ...
- mono touch登录设计
需要对MonoTouch.Dialog-1进行引用: using System; using System.Collections.Generic; using System.Linq; using ...
- 3java面试题 传智 发的 有用
第一章内容介绍 20 第二章JavaSE基础 21 一.Java面向对象 21 1. 面向对象都有哪些特性以及你对这些特性的理解 21 2. 访问权限修饰符public.private.protect ...
- bootstrap dialog 使用模态对话框
bootstrap3-dialog 使用模态对话框 <div class="modal fade"> <div class="modal-dialog& ...
- keyboard dialog 仿微博表情键盘输入框
功能描述:弹出键盘,右边有最大化按钮,没有最大化的时候最大行数为3,默认1行,随着文字输入增加自动增加高度,到达3行时不会在增加,点击最大化输入框,行数无限制,输入框下方图片点击删除 此处为了简便,键 ...
- 关于EasyUI datagrid 无法在dialog中显示的问题分析及解决方案!
最近项目中引用了easyUI,很大程度上的简化了开发过程,但是随之而来的也遇到一些问题,比如:标题中遇到的问题,去网上搜罗了下关于这个问题的解决方案,不是说的很复杂就是干脆文不对题,国外的使用这种稍微 ...
- dialog - 从 shell 显示对话框
总览 (SYNOPSIS) dialog --clear dialog --create-rc file dialog --print-maxsize dialog common-options bo ...
随机推荐
- 升级_宽视野Oracle图形升级(升级后dbca建库)—10.2.0.1.0提拔10.2.0.5.0
***********************************************声明********************************************** 原创作 ...
- JAVA8,SPRING,ANGULARJS对项目
java8+spring+angularjs 项目应用 最近有写一个电子订单商务网站,使用JAVA8,SPRING,ANGULARJS对项目使用的技术和大家分享. 第一次写博客,哪有不对需要改正的请联 ...
- oracle_连接数_查看
查看oracle数据库的连接数以及用户 .查询oracle的连接数 select count(*) from v$session; .查询oracle的并发连接数 select count(*) ...
- Swift中文教程(一)--欢迎来到Swift的世界
原文:Swift中文教程(一)--欢迎来到Swift的世界 Apple凌晨时在WWDC发布了Swift编程语言,语法简介我很喜欢,市面上没有完整的中文教程,我在ibooks里面下载了英文原版,现在开始 ...
- BIZTALK项目中WEB引用WEBSERVICES服务时候报错
近期工作中须要完毕通过BIZTALK完毕调用WEBLOGIC公布的WebServices服务,环境搭建好后,打开VS开发工具新建一个BIZTALK项目,加入WEB引用将对方公布的地址拷贝上去,能够正常 ...
- 用fildder 查看loveuv 刷流量时通信的数据
loveuv是一个用来刷网页流量的站点,以下介绍怎么查看它刷流量时数据的传输 首先是注冊页面,邀请码UBMNEY 注冊账号登陆后,在账户资料页面http://www.loveuv.com/user/m ...
- XSS Overview
什么是XSS? 跨站脚本攻击(Cross Site Scripting):攻击者往Web页面里插入恶意脚本,当用户浏览该页面时,嵌入页面的脚本代码会被执行,从而达到恶意攻击用户的特殊目的.恶意的内容通 ...
- Java数据结构与算法(4) - ch04队列(Queue和PriorityQ)
队列: 先进先出(FIFO). 优先级队列: 在优先级队列中,数据项按照关键字的值有序,关键字最小的数据项总在对头,数据项插入的时候会按照顺序插入到合适的位置以确保队列的顺序,从后往前将小于插入项的数 ...
- iOS程序 # 启动过程
[ App 应用 ] 中文名:缺省 外文名:default 拼音:quē shěng 释义:系统默认状态 全称:缺省状态 -------------- 1.程序启动顺序 1> main.m程序入 ...
- net.sf.json 迄今 时刻 格式 办法
创作工具类 import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; import ...