项目问题记录

2021-03-15  本文已影响0人  woniu

1、有关cell的问题
给cell赋值tag不能直接这样赋值'cell.tag= indexPath.row',这样会导致复用的时候出现问题,tag的值并不是像我们想象的那样,之前也遇到过这种问题。
我们需要直接将相应的row通过方法直接传过来,这样就可以了。
2、代码编写的问题
有时候为了图省事,就忽略掉一些步骤,出现问题解决的时候就显得很棘手,都是一些细节性的问题,以后要多多注意了,想省事很可能并不省事。
3、ceil&floor
ceil:向上取整
floor:向下取整

    double price = 2423.34;
    NSLog(@"~~~~~~~~price:%lf~~~~~%f~~~~~floor:%f",price,ceil(price),floor(price));

2021-03-20 15:36:59.506902+0800 PhoneTest[82022:5986983] ~~~~~~~~price:2423.340000~~~~~2424.000000~~~~~floor:2423.000000
4、字典转模型MJ
走点心吧,太久不用最简单的自己都不知道怎么用了。

//嵌套字典转化
+(NSDictionary *)mj_objectClassInArray {
    return @{@"ad_info": NSStringFromClass([YQArtDetailModel class]),
             @"ads" : NSStringFromClass([YQArtDetailModel class])
             };
}

@end

//特殊字符转化
@implementation YQArtDetailModel
- (void)setId:(NSString *)id {
    _id = id;
    self.ad_id = id;
}
//替换字符
+(NSDictionary *)mj_replacedKeyFromPropertyName
{
    return @{@"descriptionStr": @"description",
             @"ad_name":@"name",
             @"ad_content":@"content",
    };
}
//嵌套字典转化
+(NSDictionary *)mj_objectClassInArray {
    return @{@"adExt": NSStringFromClass([YQArtDetailadExtModel class]),
             };
}
@end

@implementation YQArtDetailadExtModel

@end

5、UITableViewCell中的CollectionViewCell的gif动画在表滑出界面再划回来之后,动画停止。
1、在添加到TableViewCell中的UIView类中,添加刷新方法:

-(void)reload; .h文件
-(void)reload{
    [self.collectionView reloadData];
}

2、在外部tableview滑动的时候,获取当前页面所有的存在的cell,然后所有的cell调用reloadData刷新。

-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    [self.starClassView reload];
    [self.myActiveView reload];
    [self.adView reload];
    [self.toolsView reload];
}

对于只有一个img的界面,我们重新进行赋值即可:

-(void)reload{
    if([NSString isLegalString:self.taskListModel.task_detail.icon]){
        [self.imageView sd_setImageWithURL:[NSURL URLWithString:self.taskListModel.task_detail.icon] placeholderImage:[UIImage imageNamed:@"uc_ad_img"]];
    }

6、使用映射的方式调用类方法:


    Class webClass = NSClassFromString(@"FriesWebViewController");
    id webInstance = [[webClass alloc] init];

    if (lesson) {
        [webInstance performSelector:@selector(setLessonModel:) withObject:lesson];
    }

    if (url) {
        [webInstance performSelector:@selector(setLinkUrl:) withObject:url];
    }

    [webInstance performSelector:@selector(setWebPage:) withObject:@((int)type)];

7、一个模块调用另一个模块的方式:
利用映射,获取另一个类的数据参数:

    Class YQPCollectBusinessChecker = NSClassFromString(@"Checker");
        requestUrl = [YQPCollectBusinessChecker performSelector:@selector(joinCourseUrl)];

joinCourseUrl是个类方法,里面放着返回的数据

+(NSString*)joinCourseUrl{
    return KCourse;;
}

也可以设置一个弹框弹出。

8、富文本

   NSString *dayStr = [NSString stringWithFormat:@"%@天",self.classLearnModel.totalStudyDays];
    long dlength = self.classLearnModel.totalStudyDays.length;
    CGFloat dayWidth= [dayStr zySizeWithFont:[UIFont boldSystemFontOfSize:18] constrainedToSize:CGSizeMake(0, 30) lineBreakMode:0].width;
    
    NSMutableAttributedString *dayString = [[NSMutableAttributedString alloc]initWithString:dayStr];
    [dayString addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:11/255.0 green:180/255.0 blue:180/255.0 alpha:1.0] range:NSMakeRange(0,dlength)];
    [dayString addAttribute:NSFontAttributeName value:[UIFont boldSystemFontOfSize:18] range:NSMakeRange(0, dlength)];
    [dayString addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:153/255.0 green:153/255.0 blue:153/255.0 alpha:1.0] range:NSMakeRange(dlength,1)];
    [dayString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12] range:NSMakeRange(dlength, 1)];
    NSMutableParagraphStyle *dayParagraphStyle = [[NSMutableParagraphStyle alloc] init];
    [dayString addAttribute:NSParagraphStyleAttributeName value:dayParagraphStyle range:NSMakeRange(0, [dayString length])];
    self.dayLab.textAlignment = NSTextAlignmentCenter;
    self.dayLab.attributedText= dayString;
    [self.dayLab mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.offset(dayWidth);
    }];

9、按钮上图下文,可以写一个UIButton的类别哦
可以再按钮上添加UIImageView&label,比较自由的设置大小和样式。

10、反射传参

 Class YQPAddCourseChecker = NSClassFromString(@"YQPAddCourseChecker");
                   [YQPAddCourseChecker performSelector:@selector(checkPop:skuType:) withObject:@(NO) withObject:@"shutiao_sku"];

m文件
@implementation YQPAddCourseChecker
+ (void)checkPop:(BOOL)forceDisplay skuType:(NSString *)skuType {
    
    NSString *key = @"YQPAddSubjectsNotifyChecker_1.0";
    
    BOOL haveClickedNoRemind = [[NSUserDefaults standardUserDefaults] boolForKey:key];
    BOOL haveThisSkuType = [[NSUserDefaults standardUserDefaults] boolForKey:skuType];
    
    if ((haveClickedNoRemind || haveThisSkuType) && !forceDisplay) {
        return;
    }
    
    if (skuType.length >= 0) {
        [[NSUserDefaults standardUserDefaults] setBool:true forKey:skuType];
    }
    
    YQPBusinessPopView *pop = [[YQPBusinessPopView alloc] init];
    [pop setTitle:@"已帮你加入我的课程" subTitle:@"下次可以在“孩子”查看我的课程" image:[UIImage imageNamed:@"YQPAddSubjectsNotify"]];
    [pop setNoRemindBlock:^(BOOL isSelected) {
        if(isSelected){
            [[NSUserDefaults standardUserDefaults] setBool:true forKey:key];
        }
    }];
    [pop show];
}

11、字典合并字典
将两个字典合并成一个字典。

    NSMutableDictionary *dic1 = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"BMW",@"CarLogo",@"Red",@"CarColor", nil];
    NSDictionary *dic2 = [NSDictionary dictionaryWithObjectsAndKeys:@"Xiaoming",@"name",@"28", @"age",nil];
    [dic1 addEntriesFromDictionary:dic2];
上一篇 下一篇

猜你喜欢

热点阅读