简化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 ...
随机推荐
- hdu 1533 Going Home 最小费用流
构建地图非常easy bfs预处理地图.距离的成本 来源所有m建方,流程1费0 m所有H建方,流程1距离成本 H汇点建设成为各方.流程1费0 #include<cstdio> #inclu ...
- hdu 4445 Crazy Tank (暴力枚举)
Crazy Tank Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- Android JNI环境要SQLite加密模块简介
免费的SQLite开源源代码仅仅给提供了两个函数,仅仅有实现这两个函数才干实现数据库总体加密. 然后废了点劲从网上找了一个已经实现好的开源库http://sourceforge.net/project ...
- 用Maven整合SpringMVC+Spring+Hibernate 框架,实现简单的插入数据库数据功能
一.搭建開始前的准备 1.我用的MyEclipse2014版,大家也能够用IDEA. 2.下载Tomcat(免安装解压包).MySQL(zip包下载地址 免安装解压包,优点就是双击启动,最后我会把ba ...
- MySQL汇总数据
汇总数据 有时,数据本身是不上台面的操作数据表.但在摘要表中的数据.例如 数据的一列的平均值.极大值.至少值等一下. 对于这些频繁使用的数据的处理的概要,MySQL它提供了一个函数来处理. SQL聚集 ...
- div元素上下左右居中
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...
- php禁用一些重要功能
passthru() 功能叙述性说明:我们同意将运行外部程序和回音输出.分类似至 exec(). 临界水平:高 exec() 功能叙述性说明:同意运行外部程序(例如 UNIX Shell 要么 CMD ...
- ListView排序并隔色显示
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.C ...
- Notepad++ 配置 支持jquery、html、css、javascript、php代码提示
原文:Notepad++ 配置 支持jquery.html.css.javascript.php代码提示 官网下载:http://notepad-plus-plus.org/ 获取插件的方法:打开软件 ...
- high performance program (SSE4.2 intrin instruction)
In file included from mm_lddqu.si128.c:2:0: /usr/local/lib/gcc/x86_64-redhat-linux/4.7.1/include/nmm ...