UI基础知识汇总 (part 3)
概念部分
UITableView上的footerView
- footerView的宽度永远与tableView的宽度一致, 无法修改
- footerView的y值永远为0, 无法修改
- 只能修改footerView的x值和height值
代码部分
延迟方法(延迟1秒)
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
//coding.....
});
在自定义view类中, 哪个方法(事件)表示当前的View加载完毕后执行呢?
- (void)awakeFromNib
tableView的刷新方法:
-
全部刷新
[self.tableView reloadData];
-
局部刷新(注意: 不能添加新数据, 只能修改旧数据, 只能用于tableView总行数不变的情况下刷新数据(删除原来某行, 替换成某行), 对于原来没有的行, 删除的时候会报错!)
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:self.tgs.count - 1 inSection:0]; [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
-
插入数据刷新(可以添加新数据)
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:self.tgs.count - 1 inSection:0]; [self.tableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
-
当刷新完毕后让最后一行滚动到屏幕最上方(更新到最新cell)
[self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:YES];
在自定义的UITableViewCell.m文件中重写initWithStyle方法:
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
//Coding.....
}
return self;
}
_重写此方法的目的是为了不用系统为我们cell内部创建的子控件, 而根据我们自己需求来创建cell的子控件._**
自定义一个计算字符串size的方法:
-(CGSize)sizeWithText:(NSString *)text font:(UIFont *)font maxSize:(CGSize)maxSize {
//设置一个给定的字体
NSDictionary *attrs = @{NSFontAttributeName: font};
//计算(返回)text的size
return [text boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:attrs context:nil].size;
}