iOS UI--UITableView--2--high cell

Source: Internet
Author: User

Content outline:

1、纯代码 添加子控件2、Autolayout纯代码 -- Masonry框架的使用3、自定义等高的cell -- storyboard的使用(更加简单)4、静态cell
Equal-height cell

Custom equal-height cell

    • Pure code
      • Frame
      • AutoLayout
1, Pure Code Add child control project initial preparation:
1、将Storyboard的开始默认的UIView删除,2、然后添加UITableViewController的控件,3、将UITableViewController控件设置为is init View Controller,同时设置class为ViewController,4、接着回到ViewController.h文件,将其继承UITableViewController。5、最后回到ViewController.m文件,进行纯代码操作。

Pure code operation begins:

1、实现数据源方法。<略,必须会啊,这里就不提了>2、先写好访问缓存池加载cell的代码

Originally: Then custom cell, custom control inside two methods: Add child control Method Initframe, Set child control method Layoutsubviews but: here two methods are not called, because the previous access cache pool method is called (self-supplementing)

3、新建继承UITableViewCell自定义cell,添加子控件方法initWithStyle同时调用父类的这个方法,设置子控件方法layoutSubviews

4、接着要注意的就是    <1>如果需要引用指向子控件,然后使用,取名不要和UITableViewCell自带的子控件冲突,比如self.label  detailLabel     <2>然后就是一定要先将创建的子控件对象添加进父控件,然后再用前面声明的弱引用指向它。    <3>添加子控件,一定要用self.contentView add... 不要用 self add.. 因为在这里子控件的父类建议是contentView

如果要用注册的方法循环利用cell,也是可以的,而且通过以下注册的方法,其实内部也是调用自定义cell的initWithStyle的初始化方法,是不会调用init或者initWithFrame方法的。

The next step is to set the location for the child controls

The first thing to remember:

Then start setting the child control's frame

Here we go directly to the source.

链接: http://pan.baidu.com/s/1eQrxLaM 密码: jw7c

:

AutoLayout Pure Code--the use of the masonry framework

We will find the layout of the previous pure code, if the project is complicated, the code will be very disgusting, so need to use the framework. If you want to continue to use the code in the previous chapter, please refer to the source code of the-(void) Layoutsubviews method All deleted, because this is not required to set the child control layout.

First is the masonry framework of Baidu Cloud download

链接: http://pan.baidu.com/s/1jGrVFaY 密码: e2rq

Framework Use NOTE:

#define MAS_SHORTHAND#define MAS_SHORTHAND_GLOBALS#import "Masonry.h"

Attention:

1、除了导入头文件,还需要定义宏,而且这两个宏必须写在import之前,定义宏的作用是:会自定提供某些代码给你用。总之以上三行代码原封不动的写在文件首部。2、子控件必须加进父控件再设置约束,因为相关约束是和父控件相关的。而且是要写在创建和添加父控件之后。下面看图代码就知道了。

Summary: Mainly by knocking the code familiar with the use of the framework. Don't knock not count really will use frame.

Add to the relevant frame:

例如:CGMakeGetMaxX(控件的对象.frame),CGMakeGetCenterX(控件的对象.frame)等相关的使用,可以查看源代码查看其它的。
Custom high-level cell--the use of xib

This time, create a new Xib file and create a new class Hytableviewcell that inherits UITableViewCell used by Xib. Then write the data source method in the Viewcontroller that inherits from Uitableviewcontroller. < These preparations have been skipped. > Remember to set the class for the Xib file to be on a custom cell:

    • The main work begins:

1. In the data source method, where the write-bound data source loop uses the identity load cell is different from the previous pure code

Before:

Right now:

2. After the Xib file is set to size, then add the Uiimageview and Uilabel controls, and set the layout through the drag line.

3, then be sure to remember to drag the child control to the custom required UI class and connect.

Note The key points you must know:

通过xib加载自定义cell,不管是通过注册,还是通过在设cell的循环利用的方法,他们都不会去调用alloc-init/initWithStyle。子控件也同样。

In addition: can be in the new time:

Because the new related Xib file is the Tableviewcell control (in fact, you can drag the Tableviewcell control directly before, and I have been directly dragged UIView control, so there is no ID property), so there is the ID property set, You can set the custom cell to bind the ID:

But regardless of whether the cell's parent control is UIView or Tableviewcell in the controller code, the binding ID code is almost troublesome (the cause of the problem: because the Viewcontroller load external xib or XIB-related custom control code files, the first load is required , after all, does not belong to Viewcontroller itself in the beginning, so the latter method of storyboard is the simplest), but loading the external xib or xib-related custom control code files are also different:

Finally, xib the corresponding class file, whether it is a parent control or a method that can be overridden by a child control:

-(void)awakeFromNib{    //用于初始化控件的属性}-(void)layoutSubviews{    //用于设置子控件的布局}
Custom high-level cell-Storyboard use (simpler)

As with the previous xib operation for storyboard, add child controls, set the layout of child controls, drag the lead, and so on. This is not a tiring statement.

Custom cell Split Line

Direct:

Related source code link: Http://pan.baidu.com/s/1i3jkmFV Password: XATP

Static cell

All of the above are dynamic cells, because dynamic cells are loaded with code and can be dynamically updated.

The static cell of the TableView is to be used. This has time to make GIF pictures.

In addition, further, not to be continued.

iOS UI--UITableView--2--high cell

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.