IOS开发基础知识--碎片22
1:设置有间距的表格行(UITableViewStyleGrouped)
.设置section的数目,即是你有多少个cell
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return ; // in your case, there are 3 cells}
.对于每个section返回一个cell
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return ;}
.设置cell之间headerview的高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{ return .; // you can have your own choice, of course}
.设置headerview的颜色
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{ UIView *headerView = [[UIView alloc] init]; headerView.backgroundColor = [UIColor clearColor]; return headerView;}
注意:需要使用 indexpath.section 来获得index,而不是用 indexpath.row
cell.textLabel.text=[NSString stringWithFormat:@"%@",[array objectAtIndex:indexPath.section]];
实例:
创建表格代码: if (!_myTableView) {
_myTableView = [[UITableView alloc] initWithFrame:CGRectMake(, CGRectGetMaxY(self.customheadView.frame), Main_Screen_Width, Main_Screen_Height-) style:UITableViewStyleGrouped];
_myTableView.backgroundColor = [UIColor clearColor];
_myTableView.showsVerticalScrollIndicator = NO;
_myTableView.showsHorizontalScrollIndicator=NO;
_myTableView.dataSource = self;
_myTableView.delegate = self;
_myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
[_myTableView registerClass:[BLSReplenishmentCell class] forCellReuseIdentifier:BLSReplenishmentViewController_CellIdentifier];
[self.view addSubview:_myTableView];
} 其它方法: #pragma mark UITableViewDataSource和UITableViewDelegate - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return ;
} //若设置为0 效果会达不到想要的
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return ;
} -(NSInteger)numberOfSectionsInTableView:(nonnull UITableView *)tableView
{
return self.recordDatalist.count;
} - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return ;
} - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
BLSReplenishmentCell *cell = [tableView dequeueReusableCellWithIdentifier:BLSReplenishmentViewController_CellIdentifier forIndexPath:indexPath];
cell.cur_Replenishment = [self.recordDatalist objectAtIndex:indexPath.section];
return cell;
} - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return [BLSReplenishmentCell cellHeight];
} - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
2:Xcode7 使用NSURLSession发送HTTP请求报错
报错内容:控制台打印:Application Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file.
解决办法:修改info.plist文件
3:对UITextField内容实时监听长度和内容
//第一步,对组件增加监听器
[textField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
...
//第二步,实现回调函数
- (void) textFieldDidChange:(id) sender {
UITextField *_field = (UITextField *)sender;
NSLog(@"%@,%d",[_field text],_field.text.length);
}
4:真机调试报Please verify that your device's clock is properly set, and that your signing certificate is not expired
注意:在Tagers-build Settings--Code signing--Code Signing Identity 中的Any IOS SDK记得选对证书
5:给UIAlertView增加UITextView,并获得它的值
MjyAlterView.h #import <UIKit/UIKit.h>
#import "UIPlaceHolderTextView.h" typedef void(^AlertViewBlock)(NSInteger index,NSString *textValue); @interface MjyAlterView : UIAlertView @property (nonatomic,copy)AlertViewBlock block; - (instancetype)initWithTitle:(NSString *)title message:(NSString *)message cancelButtonTitle:(NSString *)cancelButtonTitle otherButtonTitles:(NSString *)otherButtonTitles clickButton:(AlertViewBlock)block; @end MjyAlterView.m #import "MjyAlterView.h" @interface MjyAlterView()<UIAlertViewDelegate,UITextViewDelegate>
@property(copy,nonatomic)NSString *content;
@end @implementation MjyAlterView - (instancetype)initWithTitle:(NSString *)title message:(NSString *)message cancelButtonTitle:(NSString *)cancelButtonTitle otherButtonTitles:(NSString *)otherButtonTitles clickButton:(AlertViewBlock)block{ self = [super initWithTitle:title message:message delegate:self cancelButtonTitle:cancelButtonTitle otherButtonTitles:otherButtonTitles, nil];
self.backgroundColor = [UIColor whiteColor];
UIPlaceHolderTextView *textView = [[UIPlaceHolderTextView alloc]init];
textView.delegate=self;
textView.font=[UIFont systemFontOfSize:];
textView.placeholder=@"输入内容";
textView.layer.borderColor=[UIColor grayColor].CGColor;
textView.layer.borderWidth=0.5;
// if (SYSTEM_VERSION_LESS_THAN(@"7.0"))//当系统为IOS7时
// {
// [testAlert addSubview: textView];
// }
// else//当系统为IOS8
// {
[self setValue: textView forKey:@"accessoryView"];
// }
if (self) {
_block = block;
} return self; } #pragma mark UIAlertViewDelegate - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (_block != nil) {
_block(buttonIndex,self.content);
}
} #pragma mark UITextViewDelegate - (void)textViewDidChange:(UITextView *)textView{
self.content=textView.text;
} @end
调用:
__weak ViewController *weakThis = self;
AlertViewBlock block = ^(NSInteger index,NSString *content) {
__strong ViewController *strongThis = weakThis;
if (index == ) {
NSLog(@"确定,--%@",content);
}else if (index == ){ strongThis.showLabel.text = @"取消";
}
}; MjyAlterView *alterView = [[MjyAlterView alloc] initWithTitle:@""message:@""cancelButtonTitle:nil otherButtonTitles:@"确定" clickButton:block]; [alterView show];
6:iOS UILabel显示HTML文本(IOS7以上)
NSString * htmlString = @"<html><body> Some html string \n <font size=\"\" color=\"red\">This is some text!</font> </body></html>";
NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[htmlString dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
UILabel * myLabel = [[UILabel alloc] initWithFrame:self.view.bounds];
myLabel.attributedText = attrStr;
[self.view addSubview:myLabel];
运用实例(自动高度)
if (self.contentLabel==nil) {
self.contentLabel=[[UILabel alloc]init];
self.contentLabel.textColor=COLOR_WORD_GRAY_1;
self.contentLabel.font=[UIFont systemFontOfSize:];
self.contentLabel.numberOfLines=;
[self.contentLabel sizeToFit];
[self.contentView addSubview:self.contentLabel];
[self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.contentView.left).with.offset(leftSpace);
make.right.mas_equalTo(self.contentView.right).with.offset(-leftSpace);
make.top.mas_equalTo(self.lineView.bottom).with.offset(topSpace);
}];
} 赋值:
NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[model.content dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
self.contentLabel.attributedText = attrStr;
IOS开发基础知识--碎片22的更多相关文章
- IOS开发基础知识碎片-导航
1:IOS开发基础知识--碎片1 a:NSString与NSInteger的互换 b:Objective-c中集合里面不能存放基础类型,比如int string float等,只能把它们转化成对象才可 ...
- IOS开发基础知识--碎片16
1:Objective-C语法之动态类型(isKindOfClass, isMemberOfClass,id) 对象在运行时获取其类型的能力称为内省.内省可以有多种方法实现. 判断对象类型 -(BOO ...
- IOS开发基础知识--碎片19
1:键盘事件顺序 UIKeyboardWillShowNotification // 键盘显示之前 UIKeyboardDidShowNotification // 键盘显示完成后 UIKeyboar ...
- IOS开发基础知识--碎片33
1:AFNetworking状态栏网络请求效果 直接在AppDelegate里面didFinishLaunchingWithOptions进行设置 [[AFNetworkActivityIndicat ...
- IOS开发基础知识--碎片42
1:报thread 1:exc_bad_access(code=1,address=0x70********) 闪退 这种错误通常是内存管理的问题,一般是访问了已经释放的对象导致的,可以开启僵尸对象( ...
- IOS开发基础知识--碎片50
1:Masonry 2个或2个以上的控件等间隔排序 /** * 多个控件固定间隔的等间隔排列,变化的是控件的长度或者宽度值 * * @param axisType 轴线方向 * @param fi ...
- IOS开发基础知识--碎片3
十二:判断设备 //设备名称 return [UIDevice currentDevice].name; //设备型号,只可得到是何设备,无法得到是第几代设备 return [UIDevice cur ...
- IOS开发基础知识--碎片11
1:AFNetwork判断网络状态 #import “AFNetworkActivityIndicatorManager.h" - (BOOL)application:(UIApplicat ...
- IOS开发基础知识--碎片14
1:ZIP文件压缩跟解压,使用ZipArchive 创建/添加一个zip包 ZipArchive* zipFile = [[ZipArchive alloc] init]; //次数得zipfilen ...
随机推荐
- ASP.NET MVC之文件上传【二】(九)
前言 上一节我们讲了简单的上传以及需要注意的地方,查相关资料时,感觉上传里面涉及到的内容还是比较多,于是就将上传这一块分为几节来处理,同时后续也会讲到关于做上传时遗漏的C#应该注意的地方,及时进行查漏 ...
- es6分享——变量的解构赋值
变量的解构赋值:ES6 允许按照一定模式,从数组和对象中提取值,对变量进行赋值,这被称为解构(Destructuring). 以前的写法: var a = 1; var b = 2; es6允许的写法 ...
- Java多线程系列目录(共43篇)
最近,在研究Java多线程的内容目录,将其内容逐步整理并发布. (一) 基础篇 01. Java多线程系列--“基础篇”01之 基本概念 02. Java多线程系列--“基础篇”02之 常用的实现多线 ...
- Freemark笔记
Freemark基本语法知识 Freemark 常用代码总结1 Freemark 常用代码总结2 笔记,吐槽一下freemark的蛋疼语法. 1.elseif 中间不能有空格 2.三目运算符 语法和j ...
- Android测试提升效率批处理脚本(二)
前言: 前面放出过一次批处理,本次再放出一些比较有用的批处理(获得当前包名.查看APP签名信息等),好长时没来写博客了,简单化,请看正文,更多脚本尽请期待~~~(不定期) 目录 1.[手机录屏(安卓4 ...
- OpenCV,计算两幅图像的单应矩阵
平面射影变换是关于其次3维矢量的一种线性变换,可以使用一个非奇异的$3 \times 3$矩阵H表示,$X' = HX$,射影变换也叫做单应(Homography).计算出两幅图像之间的单应矩阵H,那 ...
- Halcon11与VS2010联合开发
刚开始学习Halcon,需要使用Halcon与C++联合开发软件,查了网上的资料都是Halcon10的,我用的是Halcon11和VS2010的开发环境,实践了一下发现有一些问题,于是把自己的配置的过 ...
- [PHP]Maximum execution time of 30 seconds exceeded
前言 在使用PHP渲染页面页面的时候,如果程序处理的时间特别久,超过配置文件(php.ini)设置的超时时间,就会出现如下提示: Maximum execution time of 30 second ...
- C#正则表达式Regex常用匹配
使用Regex类需要引用命名空间:using System.Text.RegularExpressions; 利用Regex类实现验证 示例1:注释的代码所起的作用是相同的,不过一个是静态方法,一个是 ...
- GBDT的基本原理
这里以二元分类为例子,给出最基本原理的解释 GBDT 是多棵树的输出预测值的累加 GBDT的树都是 回归树 而不是分类树 分类树 分裂的时候选取使得误差下降最多的分裂 计算的技巧 最终分裂收益按照下面 ...