iOS中一个tableView中显示两种cell的问题
来源:互联网 发布:宣传片制作软件下载 编辑:程序博客网 时间:2024/05/22 06:25
首先上效果图,关于昵称 时间的显示用到了富文本,后面会介绍.
1 首先说一下,在一个tableView中显示两个cell的问题 ,以XIB为例
上代码
/**
* 注册cell
*/
[self.tableListregisterNib:[UINibnibWithNibName:@"CKFriendsCell"bundle:nil]forCellReuseIdentifier:@"CKFriendsCell"];
[self.tableListregisterNib:[UINibnibWithNibName:@"CKFriendFocusCell"bundle:nil]forCellReuseIdentifier:@"CKFriendFocusCell"];
}
#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
returnself.arraySource.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
CKFriendsModel *friendModel = self.arraySource[indexPath.row];
if (friendModel.type ==101) {//用户关注了某人
CKFriendFocusCell *mycell = [tableViewdequeueReusableCellWithIdentifier:@"CKFriendFocusCell"];
mycell.friendModel = self.arraySource[indexPath.row];
//给iconView添加单点手势
UITapGestureRecognizer *tapGesturRecognizer=[[UITapGestureRecognizeralloc]initWithTarget:selfaction:@selector(clickImageView)];
mycell.iconView.userInteractionEnabled =YES;
[mycell.iconView addGestureRecognizer:tapGesturRecognizer];
//去除选中时候的灰色背景
mycell.selectionStyle =UITableViewCellSelectionStyleNone;
return mycell;
}
CKFriendsCell *cell = [tableViewdequeueReusableCellWithIdentifier:@"CKFriendsCell"];
cell.friendModel = self.arraySource[indexPath.row];
//去除选中时候的灰色背景
cell.selectionStyle =UITableViewCellSelectionStyleNone;
return cell;
}
2 关注富文本的问题
富文本在iOS开发中多用于图文混排 还是比较强大的,我们一起来看一下他的头文件吧
实例化方法:
使用字符串初始化
- (id)initWithString:(NSString *)str;
例:
NSMutableAttributedString *AttributedStr = [[NSMutableAttributedStringalloc]initWithString:@"我是bboyhzigang"];
- (id)initWithString:(NSString *)str attributes:(NSDictionary *)attrs;
字典中存放一些属性名和属性值,如:
NSDictionary *attributeDict = [NSDictionarydictionaryWithObjectsAndKeys:
[UIFontsystemFontOfSize:15.0],NSFontAttributeName,
[UIColorredColor],NSForegroundColorAttributeName,
NSUnderlineStyleAttributeName,NSUnderlineStyleSingle,nil];
NSMutableAttributedString *AttributedStr = [[NSMutableAttributedStringalloc]initWithString:@"我是bboyhzigang" attributes:attributeDict];
- (id)initWithAttributedString:(NSAttributedString *)attester;
使用NSAttributedString初始化,跟NSMutableString,NSString类似
使用方法:
为某一范围内文字设置多个属性
- (void)setAttributes:(NSDictionary *)attrs range:(NSRange)range;
为某一范围内文字添加某个属性
- (void)addAttribute:(NSString *)name value:(id)value range:(NSRange)range;
为某一范围内文字添加多个属性
- (void)addAttributes:(NSDictionary *)attrs range:(NSRange)range;
移除某范围内的某个属性
- (void)removeAttribute:(NSString *)name range:(NSRange)range;
常见的属性及说明
NSFontAttributeName 字体
NSParagraphStyleAttributeName 段落格式
NSForegroundColorAttributeName 字体颜色
NSBackgroundColorAttributeName 背景颜色
NSStrikethroughStyleAttributeName删除线格式
NSUnderlineStyleAttributeName 下划线格式
NSStrokeColorAttributeName 删除线颜色
NSStrokeWidthAttributeName删除线宽度
NSShadowAttributeName 阴影
更多方法和属性说明详见苹果官方说明文档:
https://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSMutableAttributedString_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40003689
上代码
//朋友名字
NSString *nameStr = friendModel.actor[@"name"];
str = [NSString stringWithFormat:@"%@ %@",friendModel.actor[@"name"],dateString];
NSMutableAttributedString *attstr = [[NSMutableAttributedStringalloc] initWithString:str];
[attstr addAttributes:@{NSFontAttributeName:[UIFontsystemFontOfSize:12.f]
} range:NSMakeRange(0, nameStr.length)];
[attstr addAttributes:@{NSFontAttributeName:[UIFontsystemFontOfSize:9.f]
} range:NSMakeRange(nameStr.length +2,dateString.length)];
self.nameLabel.attributedText = attstr;
- iOS中一个tableView中显示两种cell的问题
- IOS中TableView的cell显示问题
- IOS开发 tableview中cell的用法
- IOS开发 tableview中cell的用法
- IOS开发 tableview中cell的用法
- IOS中点击TableView的Cell跳转
- IOS开发 tableview中cell的用法
- iOS 中去掉tableview中多余的cell
- 去除tableView中多余的显示的cell和下划线
- iOS 中tableview的headerView高度变化是覆盖cell的问题
- tableview中cell的设置
- tableview中cell的设置
- iOS中tableView的cell的重用机制
- IOS中tableView的cell的复用机制-许笑欢
- IOS-TableView里面cell的显示动画
- UIMenuItem在tableview中对应cell显示
- IOS TableView中Cell的重用reuse机制分析
- iOS-tableView中cell的复用机制
- Struts2 namespace
- leetcode(92) Reverse Linked List II
- 9-题目1186:打印日期
- 【慕课笔记】第二章 认识JAVA中的字符串 第2节 JAVA中字符串的不变性
- altium designer 重新给文件命名
- iOS中一个tableView中显示两种cell的问题
- 关于跳槽与工资的事
- 图片加载库Glide用法
- java 虚拟机访问对象的两种机制到底有什区别 http://www.cnblogs.com/h2-database/archive/2012/06/27/2572498.html
- 堆排序 HeapSort
- 线性布局 LinearLayout
- java - 锁
- Hibernate
- Android_ListView_有Header或Footer时onItemClick里的position的问题