zoukankan      html  css  js  c++  java
  • iOS开发基础知识--碎片22

     

     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.row
    cell.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 <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: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 = @"<html><body> Some html string 
     <font size="13" 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: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;
    复制代码
  • 相关阅读:
    echo 变量不加引号出错
    linux以16进制方式查看文件
    批量删除符合条件的文件
    sed删除行
    linux用户环境变量
    脚本路径问题_dirname
    shell脚本返回字符串
    关于Unix时间戳
    grunt用来压缩前端脚本
    JAVA ThreadPoolExecutor(转)
  • 原文地址:https://www.cnblogs.com/LiLihongqiang/p/5796835.html
Copyright © 2011-2022 走看看