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. Android探索之HttpURLConnection网络请求

    前言: 最近一直想着学习一下比较好的开源网络框架okhttp,想着学习之前还是先总结一下Android原生提供的网络请求.之前一直在使用HttpClient,但是android 6.0(api 23) ...

  2. VXLAN 概念(Part II)- 每天5分钟玩转 OpenStack(109)

    上一节我们介绍了 VXLAN 的封装格式以及 VTEP.今天我们将通过例子讨论 VXLAN 封装和转发包的过程,以及 Linux 对 VXLAN 的原生支持. VXLAN 包转发流程 VXLAN 在 ...

  3. geotrellis使用初探

    最近,单位领导要求我研究一下geotrellis(GITHUB地址:https://github.com/geotrellis/geotrellis,官网http://geotrellis.io/), ...

  4. php模拟数据库常用操作效果

    test.php <?php header("Content-type:text/html;charset='utf8'"); error_reporting(E_ALL); ...

  5. 《HelloGitHub月刊》第07期

    最近工作上的事比较多,<HelloGitHub>月刊第07期拖到月底才发. 本期月刊对logo和月刊的排版进行了优化,不知道大家的反馈如何,还望大家多多反馈,让<HelloGitHu ...

  6. DotNet隐藏敏感信息操作方法

    在项目中,有时候一些信息不便完全显示,只需要显示部分信息.现在提供一些隐藏敏感信息的操作方法,主要为对信息的截取操作: 1.指定左右字符数量,中间的*的个数和实际长度有关: /// <summa ...

  7. 基于STM32Cube的ADC模数采样设计

    1.背景         此实验建立在STM32F429核心板基础上,对于深刻了解STM32Cube使用具有深刻意义.利用DMA进行ADC采样,具有速度快,极大减少CPU消耗的优势,对于数据采集系统具 ...

  8. ActiveX(四) mshtml 命名空间 重要接口简介

    在上一篇随笔 ActiveX(三)ActiveX 调用 Js 中,我们已经可以获得js中window对象的强类型接口.即 mshtml.IHTMLWindow2 ,通过该接口.我们可以调用js函数.那 ...

  9. Extjs.Button 按钮

    Extjs  Button 的简单使用 ,同时调用Ajax服务 <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xh ...

  10. Devexpress RaisePropertyChanged

    所有的重载设置字段作为参数传递到指定的值,而属性提高INotifyPropertyChanged.PropertyChanged事件. 如果一个字段已经成功地改变,setProperty方法中返回真. ...