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. linux下的常用命令

    1 fg切换前后台作业 将后台作业转换为前台作业,”fg %作业号“ 2 stty改变和打印终端行设置 tostop 阻止后台作业写终端,stty -a显示终端的所有选项 3 uname查看机子信息 ...

  2. 2014 Visual Studio Contact(); 直播笔记

    昨天微软干了几件了不起的事:.NET开发环境将开源.跨平台支持(Mac OS X和Linux).多设备支持(WP.Android和iOS)和Visual Studio免费(Visual Studio ...

  3. IDDD 实现领域驱动设计-架构之经典分层

    上一篇:<IDDD 实现领域驱动设计-上下文映射图及其相关概念> 在<实现领域驱动设计>书中,分层的概念作者讲述的很少,也就几页的内容,但对于我来说,有很多的感触需要诉说.之前 ...

  4. Java多线程系列--“JUC锁”02之 互斥锁ReentrantLock

    本章对ReentrantLock包进行基本介绍,这一章主要对ReentrantLock进行概括性的介绍,内容包括:ReentrantLock介绍ReentrantLock函数列表ReentrantLo ...

  5. Git代码管理工具

    Git代码管理工具 Git 是分布式的源代码管理工具,这点区别于svn -让源代码可以被追溯,主要是记录了每次的更新了什么,如果新版本不想用,那么则可以退回之前的版本 -Git 是Linux之父当年为 ...

  6. JS打印对象的方法&将Object转换为String的函数

    1.有时候需要把对象中的字段属性打印出来,下面用JS实现输出对象: function writeObj(obj) { var description = ""; for (var ...

  7. MongoDB初学

    参考:MongoDB 教程 | 菜鸟教程 安装 1.下载安装,从官网下载winows安装包,安装到d盘(注意路径) 2.由于我安装在d盘,所以在d盘创建文件夹data,里面创建db文件夹 3.启动方法 ...

  8. 敏捷开发Scrum

  9. Nancy之Cache的简单使用

    一.前言 说起缓存,或许大家都不陌生,甚至是天天都在用!当然缓存也被分的越来越细,页面缓存.数据缓存.文件缓存等等. 其实呢,我个人觉得,主要还是两大类:数据的缓存和页面的缓存.数据缓存的话就包括所有 ...

  10. 【转】 App架构设计经验谈:接口的设计

    App与服务器的通信接口如何设计得好,需要考虑的地方挺多的,在此根据我的一些经验做一些总结分享,旨在抛砖引玉. 安全机制的设计 现在,大部分App的接口都采用RESTful架构,RESTFul最重要的 ...