iOS开发问题归纳

162 阅读5分钟

1、做iOS 10的本地推送

  • (nullable NSURL *)URLForResource:(nullable NSString *)name withExtension:(nullable NSString *)ext API_AVAILABLE(macos(10.6), ios(4.0), watchos(2.0), tvos(9.0));返回空值

原因是需要拷贝进来image.png

2、单例

+ (instancetype)shared {
    return [[self alloc] init];
}

+ (instancetype)allocWithZone:(struct _NSZone *)zone {
    static id instance;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        instance = [super allocWithZone:zone];
    });
    return instance;
}

3、通知刷新 可以 修改为本地数据和网络数据同时修改(eg:删除操作post成功时,修改本地数据,减少一次网络请求 -> 通知刷新)

4、accessKey 内部校验,进行安全验证

5、网络状态码 www.lampweb.org/seo/5/10.ht…

6、push UIImagePickerViewController? 不能push导航控制器 只能模态出来

7、关于网络获取alert问题,解决方式

1)WiFi 下,临时启动蜂窝网络的无线网络助理,就能弹出那个允许使用数据了

2)如果在权限列表里 修改别的APP的权限 这个APP可能会重新刷新 出在列表里

8、AVPlayer 循环播放     加通知    // 跳到最新的时间点开始播放    [_player seekToTime:CMTimeMake(0, 1)]; [_player play]

9、Xcode8.0 打印问题 OS_ACTIVITY_MODE -> Disable

10、正式包 只有描述文件,没有证书,报错误xxx doesn't include signing certificate "iPhone Distribution链接手机也可以调试,因为这个开发状态

11、swift中弱化self           [weak self]  in  guard let strongSelf = self else { return }

12、tableview去除多余空白cell           tableView.tableFooterView = UIView()

13、滑动scrollView时 隐藏键盘          scrollView.keyboardDismissMode = .OnDrag

14、开关提示音  监听开关的改变状态,默认开启,APP杀死,后台,均为后台push一个音效,如果再APP中关闭提示音,可以让后台中的sound字段不传递,则无音效

15、在AppDelegate中present控制器时,需要拿到主控制器去present

16、nav 44,状态栏 20,tabbar 49 automaticallyAdjustsScrollViewInsets = false 恢复自定义,关闭系统自适应

17、UISearchBar 非谓词:从总数组使用forin遍历每一个item,使用item小写使用hasPrefix比对 searchText的小写

18、富文本 键值对错误  libc++abi.dylib: terminating with uncaught exception of type NSException

19、func didUpdateRecentSession(recentSession: NIMRecentSession, totalUnreadCount: Int) {} app退到后台可在此方法中进行对icon的badge的修改

20、3DTouch 中的分享功能,是由系统自动实现的,正常都需要进入app进行逻辑处理,也就是说,正常添加item最多四个,加上分享item,最多五个

21、tableView的数据源文件可以使用可变数组插入新数据,并且再最后reloadData

22、枚举能定义字符串么?

     答:OC中不能定义字符串,只能定义NSInterger和NSUInterger

23、数组指定类型为什么写枚举不可以?

      答:OC中数组可以指定类型,即“泛型”,方式   NSArray <NSString *> * arr = @[];

      在OC中,指定的类型只能为 对象类型 和 block

24、基类.m方法中实现一个私有方法,子类.m方法中同名实现了一个私有方法,会走子类

25、swift代理,协议中代理如果定义为可选类型,则需要delegate?.doAction?() 这样调用,防止崩溃

26、 'weak' mayonly be applied to class and class-bound protocol types

27、

  1. @objc protocol BookTiltleViewDelegate{      optional

  2. func choiceFace()  

  3. }  

  4. protocol BookTiltleViewDelegate:class//NSObjectProtocol{  

  5. func choiceFace()  

  6. }  

28、tableview动画   guideCenterView.tableView.beginUpdates()//增删改查操作

                 guideCenterView.tableView.endUpdates()

29、enumerateObjectsUsingBlock枚举遍历

30、在imageView上添加手势需要将isUserInteractionEnabled = YES

31、国际化,指在本地配置文件CFBundleDisplayName(Icon),NSLocalizedString(@"buttonTitle", nil)配合使用

32、messary 更新约束时只需要再block中更新不同的约束就可以,相同的不需要再写一遍

33、     - (void)applicationWillEnterForeground:(UIApplication *)application {

    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.

    [application setApplicationIconBadgeNumber:0];JPUSH点击一条push清空其他push

    [application cancelAllLocalNotifications];

    [JPUSHService setBadge:0];开始受到两条推送,然后点开,角标消失,系统再发送推送,角标变为3

}

34、

  1. NSString *str1 = @"can you \n speak English";  
  2. let str = NSCharacterSet(charactersInString: "qwertyuiopasdfghjklzxcvbnm")
  3. //在str1这个字符串中搜索\n,判断有没有  
  4. if ([str1 rangeOfString:str].location != NSNotFound) {  
  5. NSLog(@"这个字符串中有\n");  
  6. }  
  7. //rangeOfString 前面的参数是要被搜索的字符串,后面的是要搜索的字符  
  8. //NSNotFound 表示请求操作的某个内容或者item没有发现,或者不存在

35、缩略图可以通过设置imageView的contentmode为A-Fill再将其切掉多余的即可

36、日历展示统一为公历         formatter/datePicker.calendar = NSCalendar(calendarIdentifier: NSCalendarIdentifierGregorian)

37、GCB直连 时时刷新 长连接

38、

    //MARK: 拨打电话
    class func callPhoneNumber(number: String) {
        if UIApplication.sharedApplication().canOpenURL(NSURL(string: "telprompt://\(number)")!) {
            UIApplication.sharedApplication().openURL(NSURL(string: "telprompt://\(number)")!)
        } else {
            let alert = UIAlertView(title: "该设备不能拨打电话\n\(number)", message: nil, delegate: nil, cancelButtonTitle: "知道了")
            alert.show()
        }
    }

39、if let语法

                //如果NIMSDK.sharedSDK().conversationManager.allRecentSessions() 有值时 将对应值赋值给array;如果没有值时不进入代码块
                if let array = NIMSDK.sharedSDK().conversationManager.allRecentSessions() {
                    strongSelf.nimSessions = array
                    Print.dlog("\(strongSelf.nimSessions.count)   \(strongSelf.nimSessions.underestimateCount())")
                }
               

40、

当ContentSize属性小于等于Frame时,将不会出发滚动

so -> ContentSize要大于 Frame

41、关于tableviewcell动画和tableview的左滑多选项github.com/pengshengso…

42、swift 中弱化 self carView.changeCarClickBlock = {[weak self] in guard let strongSelf = self else { return }

        let myCarVC = HBCMyCarViewController()
        myCarVC.hidesBottomBarWhenPushed = true
        strongSelf.belongVC?.navigationController?.pushViewController(myCarVC, animated: true)
       
    }

43、胶囊按钮

    //设置圆角
    UIBezierPath *maskPath1 = [UIBezierPath bezierPathWithRoundedRect:self.btn.bounds byRoundingCorners:UIRectCornerAllCorners cornerRadii:CGSizeMake(100, 100)];
    CAShapeLayer *maskLayer1 = [[CAShapeLayer alloc] init];
    maskLayer1.frame = self.btn.bounds;
    maskLayer1.path = maskPath1.CGPath;
    self.btn.layer.mask = maskLayer1;

#重构!!!

1、语言方法异同

swift  cellModel! is HBCTripFundInviteCellModel

oc[cellModel isKindOfClass:[HBCTripFundInviteCellModel class]]

2、泛型nsarray<nsstring *> *arrs

3、@property (nonatomic, strong) NSMutableArray *dataList;✔️

@property (nonatomic,copy) NSMutableArray *dataList; 初始化,add❌

4、OC枚举不能放非NSInteger,NSUInteger,OC指定类型不能指定枚举,只能指定对象和Block

5、[[UIPasteboard generalPasteboard] setValue:aValue forPasteboardType:UIPasteboardTypeListString[0]];

6、switch case OC应用

        switch (type) {

            case 1: case 2:

            {

           }

                break;

            case 3:

            {

                HBCDailyJourneyViewController *vc = [[HBCDailyJourneyViewController alloc] init];

                [self.navigationController pushViewController:vc animated:YES];

            }

                break;

            case 4:

            {

                HBCSingleJourneyViewController *vc = [[HBCSingleJourneyViewController alloc] init];

                [self.navigationController pushViewController:vc animated:YES];

            }

                break;

            default:

                break;

        }

7、跳转 APPStroe

        //999773808

        let commentURL = "itms-apps://itunes.[apple.com/app/id](apple.com/app/id%5C)(…)"

        let URL = NSURL(string: commentURL)

        if URL == nil {

            return

        }

        if UIApplication.sharedApplication().canOpenURL(URL!) {

            UIApplication.sharedApplication().openURL(URL!)

        }

8、动态加元素

    NSMutableArray *section1 = @[].mutableCopy;

    [self.hbc_sections removeAllObjects];

    [self.hbc_sections addObject:section1];

9、当viewdidload结束 高版本会自动reloaddata tableview

10、ios7.0 layoutSubviews 中逻辑代码需要再[super layoutSubviews];之前,否则崩溃

11、 NSData *imageData = UIImageJPEGRepresentation(img, 0.75);

        UIImage *image = [UIImage imageWithData:imageData];

        NSData *compressData = UIImageJPEGRepresentation(img, 0.4);

        UIImage *compressedImage = [UIImage imageWithData:compressData];