iOS 小记(一)

目录:
1.过滤字符串的特殊字符
2.tableView reloadData 可以刷新区头区尾
3.字符串赋值崩溃原因
4.调整 UILabel 行间距
5.textField 使用大全
6.让图片自适应
7.textView设置参数问题
8.textField修改 Placeholder 颜色  大小
9.可变和不可不数组转换
10.NSString 操作
11.表格删除按钮自定义   表格删除方法
12.字符串中是否包含某个字符
13.tableView添加长按手势
14.当调用 tableview 上的某个 cell 的时候,如果在重用 cell 外边有对它的操作,在调用的时候会重新操作一次,相当于刷新该 cell
15.重新调用继承的父类的方法,相当于重写,原来父类的方法操作不再执行
16.封装的富文本方法,
17.判断两个数组是否有不同元素
18.获取网页高度
19.常见崩溃原因
20.获取app的 icon 版本号
21.分页(单个 列表上啦 下拉功能)
22.tableview 的 textlabe 距离屏幕左边缘右边距 屏幕宽375及以下15大于375 是20 textView 文字距离 textView 左边缘5
23.tableView 的自定义 cell 的属性值,在对应的区或行才可以取到,所以要再 cellforrow 需要判断下
24.获取对应 btn对应cell 的 indexPath,
25.获取当前选择的 cell 的 indexPath
26.获取时间的准确值
27.限制 tableview 到顶部不继续下拉
28.显示和隐藏系统的隐藏文件
29.QQ 分享无法跳转回 APP?
30.更改 cell.imageView的大小
31.获取字符串中的数字
32.给 tableView 添加下拉之后的背景
33.去除多余打印日志
@34.通知的使用注意事项

@1.


@3.

把nsnumber->nesting
@4.


@5.
http://blog.csdn.net/lbuskeep/article/details/28543183

@6.   imgViewLeft.contentMode = UIViewContentModeCenter;//不管图片大小 能够让图片很好展示

@7.   http://www.cnblogs.com/daguo/p/4080512.html

@8. 
KVC 修改
UITextField *txt = [[UITextField alloc] initWithFrame:CGRectMake(15, 79+i*54, G_SCREEN_WIDTH-30, 44)];
        txt.backgroundColor = [UIColor whiteColor];
        txt.placeholder = arrPlacehoder[i];
        [txt setValue:[UIColor colorWithHexString:@"666666"] forKeyPath:@"_placeholderLabel.textColor"];
        [txt setValue:[UIFont boldSystemFontOfSize:15] forKeyPath:@"_placeholderLabel.font"];

        [self.view addSubview:txt];


@9.

    1.    // NSArray --> NSMutableArray 
    2.    NSMutableArray *myMutableArray = [myArray mutableCopy]; 
    3.     
    4.    // NSMutableArray --> NSArray 
    5.    NSArray *myArray = [myMutableArray copy];
@10.
http://www.360doc.com/content/15/0213/15/19119980_448376110.shtml


@11.//设置编辑风格
-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath

{
 
    return UITableViewCellEditingStyleDelete;
}
//设置删除按钮的 title
-(NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return @"删除";
}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    switch (editingStyle) {
        case UITableViewCellEditingStyleDelete:
            
        {
            [_leftArray removeObjectAtIndex:indexPath.row];
            [_rightArray removeObjectAtIndex:indexPath.row];
            NSArray *array=@[indexPath];
            [tableView deleteRowsAtIndexPaths:array withRowAnimation:UITableViewRowAnimationAutomatic];}
            break;
            
        default:
            break;
    }

}


@12.
if([roadTitleLab.text rangeOfString:@"qingjoin"].location !=NSNotFound)//_roaldSearchText
            {
                NSLog(@"yes");
            }
            else
            {
                NSLog(@"no");
            }
@13.//
//    UILongPressGestureRecognizer *lpgr = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)];
//    lpgr.minimumPressDuration = 1.0; //seconds  设置响应时间
//    [_tableView addGestureRecognizer:lpgr]; //启用长按事件
//-(void)handleLongPress:(UILongPressGestureRecognizer *)gestureRecognizer  //长按响应函数
//{
//    if (gestureRecognizer.state == UIGestureRecognizerStateBegan) {
//        
//        CGPoint p = [gestureRecognizer locationInView:_tableView ];
//            NSIndexPath *indexPath = [_tableView indexPathForRowAtPoint:p];//获取响应的长按的indexpath
//        if (indexPath)
//        {
//            [_arrData removeObjectAtIndex:indexPath.section];
//            NSIndexSet *indexSet  =[NSIndexSet indexSetWithIndex:indexPath.section];
//            [_tableView deleteSections:indexSet withRowAnimation:UITableViewRowAnimationNone];
//            [_tableView reloadData];
//            
//        }
//        
//
//
//    }
//    
//  
//}

@16./**
 *  获取 arrtibutedString富文本
 *
 *  @param strNormal  正常颜色字符串
 *  @param colorNomal  正常颜色
 *  @param strColor   有颜色的字符串
 *  @param colorColor 有颜色的颜色
 */
- (NSMutableAttributedString *)getArrtibuteStringWithStrNormal:(NSString *)strNormal colorNomal:(UIColor *)colorNomal  andStrColor:(NSString *)strColor colorColor:(UIColor *)colorColor andFont:(NSInteger)font
{
    NSString *strAll= [NSString stringWithFormat:@"%@%@",strNormal,strColor];
    NSMutableAttributedString *strAttributed = [[NSMutableAttributedString alloc] initWithString: strAll];
    [strAttributed addAttribute: NSFontAttributeName value: [UIFont  systemFontOfSize:font] range: NSMakeRange(0, strAll.length)];
    [strAttributed addAttribute: NSForegroundColorAttributeName value: colorNomal range: NSMakeRange(0, strNormal.length)];
    [strAttributed addAttribute: NSForegroundColorAttributeName value: colorColor range: NSMakeRange(strNormal.length, strColor.length)];
    return strAttributed;
    
}


@17.
//    ios 比较俩个数组是否有不等的元素
//    方法一:利用NSPredicate
//    注:NSPredicate所属Cocoa框架,在密码、用户名等正则判断中经常用到。
//    类似于SQL语句
//    NOT 不是
//    SELF 代表字符串本身
//    IN 范围运算符
//    那么NOT (SELF IN %@) 意思就是:不是这里所指定的字符串的值
//    */
    NSPredicate * filterPredicate = [NSPredicate predicateWithFormat:@"NOT (SELF IN %@)",arr1];
    //过滤数组
    NSArray * reslutFilteredArray = [arr2 filteredArrayUsingPredicate:filterPredicate];
    NSLog(@"Reslut Filtered Array = %@",reslutFilteredArray);

输出的就是不同的元素  如果为空 就说明所含元素相同


@18.
    NSString *strHeight =[webView stringByEvaluatingJavaScriptFromString:@"document.body.offsetHeight"];
    
    [webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('body')[0].style.background='#FFFFFF'"];
    
    _webView.frame = CGRectMake(20, 10, G_SCREEN_WIDTH-40, [strHeight floatValue]);
    
    _fheight = [strHeight floatValue]+10;
    
    [_tableView reloadData];

@19.
[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[2](BaNa + 1880108)
这个问题,一般是因为 nsarray或nsdictionary插入数据为空而造成的
@20.
app icon
NSDictionary *infoPlist = [[NSBundle mainBundle] infoDictionary];
    NSString *icon = [[infoPlist valueForKeyPath:@"CFBundleIcons.CFBundlePrimaryIcon.CFBundleIconFiles"] lastObject];
    shareImage = [UIImage imageNamed:icon];
@20.
版本号
    NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
    NSString *appCurVersionNum = [infoDictionary objectForKey:@"CFBundleShortVersionString"];

@21.

属性:
    NSDictionary      *_dicItemList;
    NSMutableArray    *_marrList;
    NSInteger         _pageNO;
添加刷新



    [_tableView addHeaderWithTarget:self action:@selector(headerRefresh)];
    [_tableView setHeaderRefreshingText: @"正在帮你刷新中..."];
    [_tableView addFooterWithTarget:self action:@selector(footRefresh)];
    [_tableView setFooterRefreshingText:@"正在帮你刷新中..."];

方法

- (void)headerRefresh
{
    
    
    _pageNO = 1;
    [self queryMyWaitShareOrder:_pageNO];
    
}


- (void)footRefresh
{
    
    
    _pageNO ++;
    if (_pageNO <= [_dicItemList[@"totalPages"] integerValue ])
    {
        
        [self queryMyWaitShareOrder:_pageNO];
        
    }
    else
    {
        [_tableView footerEndRefreshing];
        
    }
}


    NSString *strPage= [NSString stringWithFormat:@"%ld",pageNO];

请求成功后的内容
    _dicItemList  = dicData;
            NSArray *arrTemp = dicData[@"result"];
            if (_pageNO == 1)
            {
                _marrList = [NSMutableArray array];
                _marrList = [arrTemp mutableCopy];
                [_tableView headerEndRefreshing];
                
            }
            else
            {
                [_marrList addObjectsFromArray:arrTemp];
                [_tableView footerEndRefreshing];
            }
            
            [_tableView reloadData];

@24.    
 MyOrderCustomCell* myCell = (MyOrderCustomCell *)btn.superview;
 NSIndexPath *cellPath = [_tableView indexPathForCell:myCell];

@25
    NSIndexPath *index = _tableView.indexPathForSelectedRow;
@26.
NSDate *currentDate = [NSDate date];//获取当前时间,日期
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"YYYY/MM/dd hh:mm:ss SS"];
    NSString *strDate = [dateFormatter stringFromDate:currentDate];

@27.
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    if (scrollView.contentOffset.y <0)
    {
        scrollView.contentOffset = CGPointMake(0, 0);
    }
}
@28.
终端:
显示:defaults write com.apple.finder AppleShowAllFiles -bool true
隐藏:defaults write com.apple.finder AppleShowAllFiles -bool false
然后重启 finder
alt + 鼠标右键(finder 上面)

@29.
配置QQ URL scheme 格式:
“QQ”+腾讯QQ互联应用appId转换成十六进制(不足8位前面补0),例如“QQ05FA957C”
“tencent“+腾讯QQ互联应用Id,例如“tencent100308348”
配置微信 URL scheme 格式:
微信应用appId,例如“wxd9a39c7122aa6516” QQ添加两个,并且 QQ 的是 APPID 的16进制字母都大写

@30. UIImage *icon = [UIImage imageNamed:@"img-12"];
            CGSize imageSize = CGSizeMake(60, 60);
            UIGraphicsBeginImageContextWithOptions(imageSize, NO,0.0); //获得用来处理图片的图形上下文。利用该上下文,你就可以在其上进行绘图,并生成图片 ,三个参数含义是设置大小、透明度 (NO为不透明)、缩放(0代表不缩放)
            CGRect imageRect = CGRectMake(0.0, 0.0, imageSize.width, imageSize.height);
            [icon drawInRect:imageRect];
            cell.imageView.image = UIGraphicsGetImageFromCurrentImageContext();
            UIGraphicsEndImageContext();
            /*
             常用的图片缩放方式这三种:
             UIGraphicsBeginImageContext // 一个基于位图的上下文(context),并将其设置为当前上下文(context)。
             UIGraphicsGetImageFromCurrentImageContext // 把当前context的内容输出成一个UIImage图片
             UIGraphicsEndImageContext // 关闭图形上下文*/
@31. //取出字符串中的数字


    /** ---------------------------------------------------------------------------*/
第一种:
字符串: urlString
    NSScanner *scanner = [NSScanner scannerWithString:urlString];
    [scanner scanUpToCharactersFromSet:[NSCharacterSet decimalDigitCharacterSet] intoString:nil];
    
    int number;
    [scanner scanInt:&number];    
    NSString *num=[NSString stringWithFormat:@"%d",number];
    

    /** ---------------------------------------------------------------------------*/

第二种:


字符串: urlString

    NSCharacterSet* nonDigits =[[NSCharacterSet decimalDigitCharacterSet] invertedSet];
    int remainSecond =[[urlString stringByTrimmingCharactersInSet:nonDigits] intValue];
    NSLog(@" num %d ",remainSecond);

@32.
    UIView *view =[[UIView alloc]initWithFrame:CGRectMake(0, -500, self.tableView.widthExt, 500)];
    view.backgroundColor = color;
    [self.tableView addSubview:view];
tableView 是 scrollView 所以可以加,也可以是图片等东西
@33.OS_ACTIVITY_MODE   disable
@34dealloc方法中移除通知(dealloc是控制器被销毁之前调用的)
[[NSNotificationCenter defaultCenter]removeObserver:<#(nonnull id)#> name:<#(nullable NSNotificationName)#> object:<#(nullable id)#>];
这是因为,当控制器因为某些原因比如内存问题而被销毁的时候,通知中心被注册的该通知还是存在的,而当其他有地方发送该通知的时候,通知中心会继续转发,但是转发的对象已经不存在了,这时候就会crash了。

posted on 2017-02-06 15:09  带我去远方  阅读(63)  评论(0)    收藏  举报

导航