简化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 ...
随机推荐
- 你的Java代码对JIT编译友好么?(转)
JIT编译器是Java虚拟机(以下简称JVM)中效率最高并且最重要的组成部分之一.但是很多的程序并没有充分利用JIT的高性能优化能力,很多开发者甚至也并不清楚他们的程序有效利用JIT的程度. 在本文中 ...
- NSString 筛选和最后一个空白、空行,多换行成一个新行
- (NSString *)filterBlankAndBlankLines:(NSString *)str { NSMutableString *Mstr = [NSMutableString st ...
- Effective C++:条款14:在中小企业资源管理copying表现
(一) 在一项条款说法auto_ptr和tr1::share_ptr适合heap-based资源.然而,并非所有的资源都heap-based的.换句话说不tr1::shared_ptr 和 auto_ ...
- 框架搭建资源 (一) V(视图)C(控制)模式
pom.xml <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncodin ...
- 【SSH三个框架】Hibernate第十篇基础:inverse属性具体解释
inverse后经常用于双向1-N在相关性.它也可以在使用N-N该协会,这里,例如用双1-N联想 或两个与各部门及工作人员,两javabean没有写. 首先,我们的员工看映射文件: <?xml ...
- Oracle\MS SQL Server Update多表关联更新
原文:Oracle\MS SQL Server Update多表关联更新 一条Update更新语句是不能更新多张表的,除非使用触发器隐含更新.而表的更新操作中,在很多情况下需要在表达式中引用要更新的表 ...
- linux下一个Oracle11g RAC建立(八)
linux下一个Oracle11g RAC建立(八) 七.安装oracle软件 直接在图形界面里安装oracle.在node1操作 在虚拟机界面中,直接切换到oracle用户下: [grid@no ...
- 采用malloc分别分配2KB个人空间,然后,realloc调整到6KB、1MB、3MB、10MB场地,分别这五内存“A”、“B”、“C”、“D”、“E”灌装
#include<stdio.h> #include<stdlib.h> #include<string.h> #include<malloc.h> i ...
- Pku1218
<span style="background-color: rgb(204, 204, 204);">/* A - THE DRUNK JAILER Time Lim ...
- IOS开发中怎样验证邮箱的合法性
IOS开发中怎样验证邮箱的合法性 文章参考:http://www.codes51.com/article/detail_94157.html 代码: - (void)viewDidLoad { [su ...