博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
iOS开发基础知识--碎片22
阅读量:6693 次
发布时间:2019-06-25

本文共 7389 字,大约阅读时间需要 24 分钟。

 

 iOS开发基础知识--碎片22

1:设置有间距的表格行(UITableViewStyleGrouped)

1.设置section的数目,即是你有多少个cell- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {    return 3; // in your case, there are 3 cells}2.对于每个section返回一个cell- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{    return 1;}3.设置cell之间headerview的高度- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{    return 10.; // you can have your own choice, of course}4.设置headerview的颜色- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{    UIView *headerView = [[UIView alloc] init];    headerView.backgroundColor = [UIColor clearColor];    return headerView;}注意:需要使用 indexpath.section 来获得index,而不是用 indexpath.rowcell.textLabel.text=[NSString stringWithFormat:@"%@",[array objectAtIndex:indexPath.section]];

实例:

创建表格代码:    if (!_myTableView) {        _myTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.customheadView.frame), Main_Screen_Width, Main_Screen_Height-204) 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 10;}//若设置为0 效果会达不到想要的- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{    return 1;}-(NSInteger)numberOfSectionsInTableView:(nonnull UITableView *)tableView{    return self.recordDatalist.count;}- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{    return 1;}- (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 
#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;@endMjyAlterView.m#import "MjyAlterView.h"@interface MjyAlterView()
@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:15]; 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 == 1) {            NSLog(@"确定,--%@",content);        }else if (index == 0){                        strongThis.showLabel.text = @"取消";        }    };        MjyAlterView *alterView = [[MjyAlterView alloc] initWithTitle:@""message:@""cancelButtonTitle:nil otherButtonTitles:@"确定" clickButton:block];    [alterView show];

 6:iOS UILabel显示HTML文本(IOS7以上)

NSString * htmlString = @" Some html string \n This is some text! ";  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:14];            self.contentLabel.numberOfLines=0;            [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;

转载地址:http://zlcoo.baihongyu.com/

你可能感兴趣的文章
Microsoft Azure部署MYSQL-MMM(2)配置主主复制
查看>>
Surface体验WS2012中RDS的RemoteFX虚拟桌面
查看>>
因为有你,所以精彩
查看>>
K8S集群中使用Helm管理应用分发
查看>>
<進階&高級>ADT線上視頻&PPT課件
查看>>
Apache 与 Nginx 比较
查看>>
杂文语录积累(二)
查看>>
隔离公司各个部门--虚拟路由器(EBGP)
查看>>
在 SELECT 查询中使用子查询
查看>>
Microsoft Lync Server 2013: 配置SQL服务器数据分发
查看>>
Zabbix 日志监控
查看>>
数据挖掘里的“降维”----从五阶魔方的玩法思考
查看>>
shell脚本实例之Charpter8-9
查看>>
Error polling connection 'qemu:///system': internal error Cannot find suitable emulator for
查看>>
iptables实战
查看>>
valgrind调试CPU缓存命中率和内存泄漏
查看>>
水星三维引擎发布2.0版本 ~友情帮介绍下~
查看>>
内外网访问NAT设置
查看>>
公开课视频-《第03章 部署-IT基础架构》-大企业云桌面部署实战-在线培训-视频(奉献)...
查看>>
数字方舟,末日起航-记2012云计算架构师峰会
查看>>