页面结构:1个UIPageViewController含多个其他ViewController,每个ViewController中又包含了一个UITableView问题:无法通过点击状态栏,让当前UITableView内容置顶原因:UIPageViewController帮助我们管理了多个ViewController,本质上在UIPageViewController的view中包含多多个ViewController中的UITableView。由于每个UITableView的scrollsToTop默认值都是YES,这样系统就无法判断点击状态栏该让哪个置顶了。解决方法:通过代码...
--UIKit之UITableView
概述
在iOS开发中UITableView可以说是使用最广泛的控件,我们平时使用的软件中到处都可以看到它的影子,类似于微信、QQ、新浪微博等软件基本上随处都是UITableView。当然它的广泛使用自然离不开它强大的功能,今天这篇文章将针对UITableView重点展开讨论。今天的主要内容包括:基本介绍数据源代理性能优化UITableViewCell常用操作UITableViewControllerMVC模式
基本介绍
UITableView有两种风格:UITableViewS...
一、UITableViewCell简介UITableView上的每一行的内容都是UITableViewCell来显示的,通过 UITableViewDataSource的协议方法:tableView:cellForRowAtIndexPath:来初始化要显示的内容。而 UITableViewCell则是通过它自带的contentView来显示,每个Cell都默认有个子视图contentView,所以每个cell 上显示的内容都是加在这个视图上。系统的UITableViewCell有四种类型 UITableViewCellStyleDefault, UITableViewCellStyleVa...
一、 封装cell:1、加载xib文件的两种方式 <方式1> (NewsCell是xib文件的名称) NSArray *objects = [[NSBundle mainBundle] loadNibNamed:@"NewsCell" owner:nil options:nil]; <方式2> UINib *nib = [UINib nibWithNibNamed:@"NewsCell" bundle:nil]; NSArry *objects = [nib instantiateWithOwner:nil options:nil]; 二、设置cell的高度 1. 如果每一行的cell高度都是一样,应该用代理方法设置cell...
#import <UIKit/UIKit.h>@interface AppDelegate : UIResponder <UIApplicationDelegate>@property (strong, nonatomic) UIWindow *window;@end#import"AppDelegate.h"#import"MovieHomeController.h"@interface AppDelegate ()@end@implementation AppDelegate- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {self.window = [[UIWindow alloc] initWithFrame:[[...
当 UITableView 中有一个 label 的内容比较长的时候,就需要 cell 自适应高度来多行展示label;首先设置 label 的 line 为0;代码如下:// 为每一个 cell 预设置一个高度,可以提高效率
- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath {return44;
}// 这里每一个 cell 的实际高度(即自适应高度)
- (CGFloat)tableView:(UITableView *)tableView heightForRowAt...
IOS学习(OC语言)知识点整理一、OC字符串的操作1)OC中字符串分为两种: 1、不可变字符串NSString:不能修改对象内容,但是可以改变对象的指针。 2、可变字符串NSMutableString:可以修改对象内容。二、NSString 不可变字符串的操作1)将字符串常量对象直接赋值给字符串引用 NSString *str1=@"hello"; 字符串对象的输出格式:NSLog(@"str1=%@",str1)。2)initWithString可将OC中的字符串对象构建字符串引用 NSString *str2=[[NS...
本文围绕以下几点展开tableView性能优化的论述?1.UITableViewCell重用机制?2.tableView滑动为什么会卡顿?3.优化方法?4.总结1.UITableViewCell重用机制?UITableView只会创建一屏幕(或者一屏幕多一点)的cell,其他都是取出来重用的。每当cell滑出屏幕的时候,就会放到一个集合中,当要显示某一位置的cell时,会先去集合中取,有的话,就直接拿出来显示,没有在创建。2.tableView滑动为什么会卡顿?cell赋值内容时,会根据内容...
(1)效果(2)源代码与资源下载http://pan.baidu.com/s/1pJLo2PP(3)总结——核心是利用UITableView里面自带的cell来制作样式相同的cell。与之相应的是,因为不是整个xib文件,所以加载这个cell时有一些区别,只需要在缓存池中取即可(利用ID)。+(instancetype)cellWithTableView:(UITableView *)tableView{static NSString *ID=@"app";WPAppCell *cell=[tableView dequeueReusableCellWithIdentifier:ID];return cell;
}
——第...
UITableView基本使用方法1.首先,Controller需要实现两个delegate ,分别是UITableViewDelegate 和UITableViewDataSource2.然后 UITableView对象的 delegate要设置为 self。3.然后就可以实现这些delegate的一些方法拉。(1)- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;这个方法返回 tableview 有多少个section//返回有多少个Sections - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableVie...
iOS开发UI篇—UITableview控件使用小结一、UITableview的使用步骤UITableview的使用就只有简单的三个步骤:1.告诉一共有多少组数据方法:- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;2.告诉每组一共有多少行方法:- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section; 3.设置每组每行(cell)方法:- (UITableViewCell *)tableView:(UITableView *)tableView cell...
tableView 实现的方法 无分组的cell#pragma mark - Table view data source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{return self.contacts.count;
}- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{// 1.创建cellMJContactCell *cell = [MJContactCell cellWithTableView:tableView];// 2.设置cell的数据cell.con...
思路: 1.new 一个 Empty 后缀为 .txt 文件,内容随笔拷贝一段 2.用 NSString 接收本地文件,再用一个标题拼接字符串 3.创建一个 NSMutableParagraphStyle 实例,设置标题居中、标题距离正文间隔 4.创建一个 NSMutableParagraphStyle 实例,设置正文左对齐、每段开头缩进 10 5.创建一个基础动画的实例,用代理监听动画结束话不多说上代码#pragma mark -- 拼接字符
- (void)loadData:(NSString *)filename {//第一个...
*****HMViewController#import"HMViewController.h"#import"HMStatus.h"#import"HMStatusCell.h"#import"HMStatusFrame.h"@interface HMViewController ()
/** 保存statusFrame模型的数组 */
@property (nonatomic, strong) NSArray *statusFrames;
@end@implementation HMViewController- (NSArray *)statusFrames
{if (_statusFrames == nil) _statusFrames = [HMStatusFrame statusFrames];return _statusFrames;
}- (void)view...
UITableView相当于Android里面的ListView,但功能却比ListView强大太多。使用UITableView需要指定数据源和代理。1.显示所有的行遵守UITableViewDataSource协议,必须实现的方法有两个:// 每一节里面有多少行
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
// 每行的View,这里是UITableViewCell
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger...