第八章 self sizing cell
本项目是《beginning iOS8 programming with swift》中的项目学习笔记==》全部笔记目录
------------------------------------------------------------------------------------------------------------------
Self Sizing Cell的设置通常有如下三个主要步骤:
找到DetailView的界面,在prototype cell中添加auto layout约束
指定TableView的estimated row height
设置row height为UITableViewAutomaticDimention
1. 修改Restaurant中的locaiton为全名(用很长的名称,使得一行显示不下):
var restaurants = [
Restaurant(name: "Cafe Deadend", type: "Coffee & Tea Shop", location: "G/F, 72 Po Hing Fong, Sheung Wan, Hong Kong", image: "cafedeadend.jpg", isVisited: false),
Restaurant(name: "Homei", type: "Cafe", location: "Shop B, G/F, 22-24A Tai Ping San Street SOHO, Sheung Wan, Hong Kong", image: "homei.jpg", isVisited: false),
Restaurant(name: "Teakha", type: "Tea House", location: "Shop B, 18 Tai Ping Shan Road SOHO, Sheung Wan, Hong Kong", image: "teakha.jpg", isVisited: false),
Restaurant(name: "Cafe loisl", type: "Austrian / Causual Drink", location: "Shop B, 20 Tai Ping Shan Road SOHO, Sheung Wan, Hong Kong", image: "cafeloisl.jpg", isVisited: false),
Restaurant(name: "Petite Oyster", type: "French", location: "24 Tai Ping Shan Road SOHO, Sheung Wan, Hong Kong", image: "petiteoyster.jpg", isVisited: false),
Restaurant(name: "For Kee Restaurant", type: "Bakery", location: "Shop J-K., 200 Hollywood Road, SOHO, Sheung Wan, Hong Kong", image: "forkeerestaurant.jpg", isVisited: false),
Restaurant(name: "Po's Atelier", type: "Bakery", location: "G/F, 62 Po Hing Fong, Sheung Wan, Hong Kong", image: "posatelier.jpg", isVisited: false),
Restaurant(name: "Bourke Street Backery", type: "Chocolate", location: "633 Bourke St Sydney New South Wales 2010 Surry Hills", image: "bourkestreetbakery.jpg", isVisited: false),
Restaurant(name: "Haigh's Chocolate", type: "Cafe", location: "412-414 George St Sydney New South Wales", image: "haighschocolate.jpg", isVisited: false),
Restaurant(name: "Palomino Espresso", type: "American / Seafood", location: "Shop 1 61 York St Sydney New South Wales", image: "palominoespresso.jpg", isVisited: false),
Restaurant(name: "Upstate", type: "American", location: "95 1st Ave New York, NY 10003", image: "upstate.jpg", isVisited: false),
Restaurant(name: "Traif", type: "American", location: "229 S 4th St Brooklyn, NY 11211", image: "traif.jpg", isVisited: false),
Restaurant(name: "Graham Avenue Meats", type: "Breakfast & Brunch", location: "445 Graham Ave Brooklyn, NY 11211", image: "grahamavenuemeats.jpg", isVisited: false),
Restaurant(name: "Waffle & Wolf", type: "Coffee & Tea", location: "413 Graham Ave Brooklyn, NY 11211", image: "wafflewolf.jpg", isVisited: false),
Restaurant(name: "Five Leaves", type: "Coffee & Tea", location: "18 Bedford Ave Brooklyn, NY 11222", image: "fiveleaves.jpg", isVisited: false),
Restaurant(name: "Cafe Lore", type: "Latin American", location: "Sunset Park 4601 4th Ave Brooklyn, NY 11220", image: "cafelore.jpg", isVisited: false),
Restaurant(name: "Confessional", type: "Spanish", location: "308 E 6th St New York, NY 10003", image: "confessional.jpg", isVisited: false),
Restaurant(name: "Barrafina", type: "Spanish", location: "54 Frith Street London W1D 4SL United Kingdom", image: "barrafina.jpg", isVisited: false),
Restaurant(name: "Donostia", type: "Spanish", location: "10 Seymour Place London W1H 7ND United Kingdom", image: "donostia.jpg", isVisited: false),
Restaurant(name: "Royal Oak", type: "British", location: "2 Regency Street London SW1P 4BZ United Kingdom", image: "royaloak.jpg", isVisited: false),
Restaurant(name: "Thai Cafe", type: "Thai", location: "22 Charlwood Street London SW1V 2DY Pimlico", image: "thaicafe.jpg", isVisited: false)
]
2. 设置Detail视图中表格的两个Label控件水平居中、Name距离左边距9点、Value距离左边距87点,距离右边距10点(最好先Reset to suggested constrain)。
3. 在Detail的viewDidLoaded方法中:
tableView.estimatedRowHeight = 36.0
tableView.rowHeight = UITableViewAutomaticDimension
4. 选中Value Label,设置行数为0,否则不会换行。
同理,对Restaurant控制器中的控件进行设置。
效果图:
第八章 self sizing cell的更多相关文章
- swift项目实战FoodPin目录
好吧,据说写博客能够找到好工作,那我也来分享一个项目吧! 自己自学iOS开发也有半年多了,现在就来分享一个swift的小项目吧!这个项目的来源是<Beginning iOS8 programmi ...
- 理解iOS 8中的Self Sizing Cells和Dynamic Type
http://www.cocoachina.com/ios/20140922/9717.html 在iOS 8中,苹果引入了UITableView的一项新功能--Self Sizing Cells,对 ...
- 第八章 Qt GUI之对话框使用
第八章 Qt GUI之对话框使用 对话框可以是模态(modal)的或非模态(modeless)两种.当我们在一个用户界面程序里面对一个对话框(比如选择文件对话框)的操作没有结束前,界面的其他窗口无法操 ...
- iOS开发之多种Cell高度自适应实现方案的UI流畅度分析
本篇博客的主题是关于UI操作流畅度优化的一篇博客,我们以TableView中填充多个根据内容自适应高度的Cell来作为本篇博客的使用场景.当然Cell高度的自适应网上的解决方案是铺天盖地呢,今天我们的 ...
- 使用Autolayout实现UITableView的Cell动态布局和高度动态改变
本文翻译自:stackoverflow 有人在stackoverflow上问了一个问题: 1 如何在UITableViewCell中使用Autolayout来实现Cell的内容和子视图自动计算行高,并 ...
- iOS - UITableView中Cell重用机制导致Cell内容出错的解决办法
"UITableView" iOS开发中重量级的控件之一;在日常开发中我们大多数会选择自定Cell来满足自己开发中的需求, 但是有些时候Cell也是可以不自定义的(比如某一个简单的 ...
- UICollectionView布局cell的三种方式
UICollectionViewFlowLayout里面: // 方法一 - (void)prepareLayout{} // 方法二 - (nullable NSArray<__kindof ...
- Cell右滑 多个编辑选项栏
简单粗暴,一看就能明白 关于右滑cell,能滑出来两个以上的选项栏,可以如下这么做,但是要注意下面的注意事项,就是关于iOS8前后的问题,注释写的很清楚了.可以直接复制到自己的代码里看的会更明白. / ...
- UICollectionViewCell--查找cell上的按钮点击后,对应的是哪个cell
实际写项目会碰到各种各样的问题,废话不多说 按钮添加到cell时,根据是直接添加到self还是self.contentView上,在点击方法里找到btn的父视图 我是直接添加到self上,所以只有一层 ...
随机推荐
- LightSpeed 相关问题处理
1. 关于KeyTable 配置文件中有一个节点 lightSpeedContexts 该节点下存放的是一些使用LightSpeed的配置,如 <add name="myDB&quo ...
- ASP.NET5 MVC6入门教学之一(自己动手)
等待微软开源大动作已经好几年了,终于ASP.NET 5发布了.今天给新手们写一个简单地教程,教你认识一下ASP.NET5 MVC6 1.安装kvm 首先,你需要以管理员权限打开cmd,执行如下的脚本: ...
- STM32启动文件选择说明
图1. STM32F10xxx标准外设库体系结构先说这个问题,大家都知道,我们在选择使用哪些外围的的时候,是去更改从官方模版中拷贝过来的stm32f10x_conf.h文件的27-48行,把我们要用的 ...
- HTML5 datalist 标签
以前需要用JS写一个自动完成组件(Suggest),很费劲.HTML5时代则不用了,直接使用datalist标签,直接减少了工作量.如下 <!DOCTYPE html> <html& ...
- APP 接口开发及读取静态缓存
<?php /** * Description: App 接口 * Create date:2015-10-19 13:36 * Author: zhaoyingnan **/ class Re ...
- NOIP2013普及组 T2 表达式求值
OJ地址:洛谷P1981 CODEVS 3292 正常写法是用栈 #include<iostream> #include<algorithm> #include<cmat ...
- NOIP2007 T2纪念品分组 解题报告-S.B.S.
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #inclu ...
- 初始化httpclient的几种方式
1.CloseableHttpClient httpclient = HttpClients.createDefault(); 2.DefaultHttpClient client = new Def ...
- 【转载】jQuery Validate 菜鸟教程
文章1:http://www.runoob.com/jquery/jquery-plugin-validate.html (jQuery Validate 菜鸟教程)
- Android Studio下载与安装
Android Studio下载与安装 1 2 3 4 5 分步阅读 百度经验:jingyan.baidu.com 自从Google宣布Android Studio将取代Eclipse,正式成为官方集 ...