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的更多相关文章

  1. IOS开发基础知识碎片-导航

    1:IOS开发基础知识--碎片1 a:NSString与NSInteger的互换 b:Objective-c中集合里面不能存放基础类型,比如int string float等,只能把它们转化成对象才可 ...

  2. IOS开发基础知识--碎片16

    1:Objective-C语法之动态类型(isKindOfClass, isMemberOfClass,id) 对象在运行时获取其类型的能力称为内省.内省可以有多种方法实现. 判断对象类型 -(BOO ...

  3. IOS开发基础知识--碎片19

    1:键盘事件顺序 UIKeyboardWillShowNotification // 键盘显示之前 UIKeyboardDidShowNotification // 键盘显示完成后 UIKeyboar ...

  4. IOS开发基础知识--碎片33

    1:AFNetworking状态栏网络请求效果 直接在AppDelegate里面didFinishLaunchingWithOptions进行设置 [[AFNetworkActivityIndicat ...

  5. IOS开发基础知识--碎片42

    1:报thread 1:exc_bad_access(code=1,address=0x70********) 闪退 这种错误通常是内存管理的问题,一般是访问了已经释放的对象导致的,可以开启僵尸对象( ...

  6. IOS开发基础知识--碎片50

      1:Masonry 2个或2个以上的控件等间隔排序 /** * 多个控件固定间隔的等间隔排列,变化的是控件的长度或者宽度值 * * @param axisType 轴线方向 * @param fi ...

  7. IOS开发基础知识--碎片3

    十二:判断设备 //设备名称 return [UIDevice currentDevice].name; //设备型号,只可得到是何设备,无法得到是第几代设备 return [UIDevice cur ...

  8. IOS开发基础知识--碎片11

    1:AFNetwork判断网络状态 #import “AFNetworkActivityIndicatorManager.h" - (BOOL)application:(UIApplicat ...

  9. IOS开发基础知识--碎片14

    1:ZIP文件压缩跟解压,使用ZipArchive 创建/添加一个zip包 ZipArchive* zipFile = [[ZipArchive alloc] init]; //次数得zipfilen ...

随机推荐

  1. 深入理解DOM节点类型第四篇——文档片段节点DocumentFragment

    × 目录 [1]特征 [2]作用 前面的话 在所有节点类型中,只有文档片段节点DocumentFragment在文档中没有对应的标记.DOM规定文档片段(document fragment)是一种“轻 ...

  2. (转)运维角度浅谈MySQL数据库优化

    转自:http://lizhenliang.blog.51cto.com/7876557/1657465 一个成熟的数据库架构并不是一开始设计就具备高可用.高伸缩等特性的,它是随着用户量的增加,基础架 ...

  3. 10个惊艳的Swift单行代码

    几年前,一篇表述“10个Scala函数式单行代码”的文章非常受欢迎,并且随后立马出现了其他的语言版本,例如Haskell版本,Ruby版本,Groovy版本,Clojure版本,Python版本,C# ...

  4. 关于BFC不会被浮动元素遮盖的一些解释

    简介 在清除浮动一文中提到BFC不会被浮动元素遮盖,并没有详细探究表现行为.规范中指出,在同一个BFC内,作为子元素的BFC的border-box不应该覆盖同为子元素的浮动元素的margin-box. ...

  5. MySQL入门03-MySQL配置安全性、易用性

    一.设定管理员用户和密码 二.处理test库权限隐患 三.自定义脚本提升易用性 中间定义文件 启动MySQL服务 关闭MySQL服务 快捷登录MySQL 四.设置开机自动启动MySQL服务 Refer ...

  6. 【十大经典数据挖掘算法】CART

    [十大经典数据挖掘算法]系列 C4.5 K-Means SVM Apriori EM PageRank AdaBoost kNN Naïve Bayes CART 1. 前言 分类与回归树(Class ...

  7. [WCF编程]10.操作:流操作

    一.流操作概述 在默认情况下,当客户端调用服务时,服务只有在接收到完整的消息后才会被调用,同样,客户端只有在包含了调用结果的返回消息被完整接受时,才会解除对它的阻塞. 对于数据量小的消息,这种交换模式 ...

  8. linq lambda left join

    //var list = table1.Join(table2, ee => ee.Id, ff => ff.table1_Id, (ee, ff) => new { ee, ff  ...

  9. Entity Framework 代码先行

    一.什么是Code First 为了支持以设计为中心的开发流程,EF还更多地支持以代码为中心 (code-centric) ,我们称为代码优先的开发,代码优先的开发支持更加优美的开发流程,它允许你在不 ...

  10. Java中随机数的产生方式与原理

    查阅随机数相关资料,特做整理 首先说一下java中产生随机数的几种方式 在j2se中我们可以使用Math.random()方法来产生一个随机数,这个产生的随机数是0-1之间的一个double,我们可以 ...