【ios开发学习】常见问题积累

来源:互联网 发布:网络舆情队伍建设 编辑:程序博客网 时间:2024/06/06 21:39

1.UITableView的常见问题:

    //设置顶部不留白

    self.automaticallyAdjustsScrollViewInsets = NO;

    //去除tableview顶部和底部的section

    tableView.tableHeaderView = [[UIView allocinitWithFrame:CGRectMake(0.0f0.0f,tableView.bounds.size.width0.001f)];

    tableView.tableFooterView = [[UIView allocinitWithFrame:CGRectMake(0.0f0.0f,tableView.bounds.size.width0.01f)];

    //去除tableview内部的section

    tableView.sectionHeaderHeight = 0.0f;

    tableView.sectionFooterHeight = 0.0f;

    //去除上拉cell之间的灰色分割线

    tableView.separatorStyle = UITableViewCellSeparatorStyleNone;

2.UITextField的常见问题

    //输入文字不在边框处开始显示,输入字符距离左边界有一定距离

    UIView *paddingView = [[UIView allocinitWithFrame:CGRectMake(00520)];

    inputCodeText.leftView = paddingView;

    inputCodeText.leftViewMode = UITextFieldViewModeAlways;

    //默认显示输入法数字键盘

    numText.keyboardType=UIKeyboardTypeNumberPad;

    //修改输入法return按钮的功能

    numText.returnKeyType =UIReturnKeyDone;

    //失去焦点,隐藏输入法

    [numTextresignFirstResponder];


3.UIButton的常见问题

    //s设置UIbutton或其它view的边界的宽度和边界颜色

    okBtn.layer.borderWidth = 1;

    okBtn.layer.borderColor = [[UIColor lightGrayColorCGColor];

    //UIbutton上可以同时设置image和title,只要是widht和不大于button的width

    [switchBtn setTitle:@"手动输入" forState:UIControlStateNormal];

    [switchBtn setImage:[UIImage imageNamed:@"back"forState:UIControlStateNormal];

    [switchBtn setTitleColor:[UIColor blackColorforState:UIControlStateNormal];

    //设置Buttonlabelimage的间距

    [switchBtn setImageEdgeInsets:UIEdgeInsetsMake(00020)]

    [switchBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, 5, 0, 0)];

    //设置UIButton的圆角按钮

    reIntoHouseBtn.layer.cornerRadius =10.0;

4.TableView加载json解析数据

    NSString *path = [[NSBundlemainBundle]pathForResource:@"data"ofType:@"json"];

    NSData *jsonData = [NSDatadataWithContentsOfFile:pathoptions:NSDataReadingMappedIfSafeerror:nil];

    id jsonObj = [NSJSONSerializationJSONObjectWithData:jsonDataoptions:NSJSONReadingAllowFragmentserror:nil];

    NSMutableArray *arrayM = [jsonObjobjectForKey:@"data"];

    NSMutableArray *tempArray = [[NSMutableArrayalloc]init];

    for (NSDictionary *dictin arrayM) {

        GoodsModel *goodsModel = [[GoodsModelalloc]init];

        //goodsModel赋值

        [goodsModel setValuesForKeysWithDictionary:dict];

        [tempArray addObject:goodsModel];

    }

    dataList = tempArray;

5.UIImageView上添加Button,不能触发点击事件
------解决方案-------------------- 
因为UIImageView 默认是不接受Touch事件的  
所以只要加上一句imgView.userInteractionEnabled = YES;                





               
0 0
原创粉丝点击