#### has not updated for a long time. Today, I write some problems that I or my colleagues encounter at ordinary times, as a memo. #####1. The number accuracy of iOS11 is incorrect

/ *! @brief Corrects floating point accuracy loss @param STR incoming interface data @returnCorrection of precision data */ +(NSString *)reviseString:(NSString *) STR {// directly pass in the wrong type of Double Double conversionValue = [STR doubleValue]; NSString *doubleString = [NSString stringWithFormat:@"%lf", conversionValue];
    NSDecimalNumber *decNumber = [NSDecimalNumber decimalNumberWithString:doubleString];
    return [decNumber stringValue];
}
Copy the code

#####2. IOS 11 TableView adaptation

// tableView offset 20/64 fitif(@ the available (iOS 11.0. *)) {self. TableView. ContentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; //UIScrollView also applies}else {
    self.automaticallyAdjustsScrollViewInsets = NO;
}
Copy the code

#####3. IOS 11 map does not ask you whether to allow location

Privacy-location Always Usage Description // Delete this iOS11 can prompt privacy-location When In Use Usage DescriptionCopy the code

#####4. Amap click gesture to add markers for POI retrieval

Method 1: Click the map on the screen to obtain the longitude and latitude of the gesture click point and perform POI retrieval. Add gesture UITapGestureRecognizer *mTap = [[UITapGestureRecognizer alloc] initWithTarget:self Action :@selector(tapPress)]; mTap.delegate = self; [self.mapView addGestureRecognizer:mTap]; 2. Gesture method - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {returnYES; } - (void)tapPress:(UIGestureRecognizer*)gestureRecognizer { CGPoint touchPoint = [gestureRecognizer locationInView:self.mapView]; Cllocation2d touchMapCoordinate = [self.mapView convertPoint:touchPoint toCoordinateFromView:self.mapView]; / / touchMapCoordinate here is the latitude and longitude of the point at which a AMapPOIAroundSearchRequest * request = [[AMapPOIAroundSearchRequest alloc] init]; request.location = [AMapGeoPoint locationWithLatitude:touchMapCoordinate.latitude longitude:touchMapCoordinate.longitude]; */ request. Sortrule = 0; request.requireExtension = YES; [self.search AMapPOIAroundSearch:request];Copy the code

#####5. Multi-layer WkWebView returns

    if ([self.localWebView canGoBack]) {
        [self.localWebView goBack];
    } else {
        [self.navigationController popToRootViewControllerAnimated:YES];
    }
Copy the code

#####6. Tableview array out of bounds

  • Remove all array elements when creating only one refresh using lazy-loaded arrays
[self.dataArray removeAllObjects];
Copy the code
  • [tableVIew reloadData] [tableVIew reloadData] In this case, a judgment needs to be made:
if(self.dataArray.count ! = 0){ MOdel * model = self.dataArray[indexPath.row]; }Copy the code
  • Row > the number of elements in the array is equal to the number of elements. So you need to do the following
 if(! (indexPath.row > rewardArray.count)){ Model* model = slef.dataArray[indexpath.row]; }Copy the code

#####7. Textfiled Placeholder Settings

      NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
        attrs[NSForegroundColorAttributeName] = [Toolkit getColor:@"ff5600"];
        NSMutableAttributedString *placeHolder = [[NSMutableAttributedString alloc]initWithString:@"Please enter your payment password" attributes:attrs];
        _zhifuTextField.attributedPlaceholder = placeHolder;

Copy the code

#####8. Do not slide back

-(void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; // Disable the return gestureif ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)])
    {
        self.navigationController.interactivePopGestureRecognizer.enabled = NO;
    }
}
- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)])
    {
        self.navigationController.interactivePopGestureRecognizer.enabled = YES;
    }
Copy the code

#####9. Set the label line

/ / crossed NSMutableAttributedString * attribtStr_origin = [[NSMutableAttributedString alloc] initWithString: originalMoney attributes:attribtDic]; [attribtStr_originsetAttributes:@{NSStrikethroughStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleSingle], NSBaselineOffsetAttributeName : @(NSUnderlineStyleSingle),NSForegroundColorAttributeName:[Toolkit getColor:hex_aaaaaa]} range:NSMakeRange(0,attribtStr_origin.length)];

    [attribtStr_origin addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"GillSans"Size: 12.0] range: NSMakeRange (0, attribtStr_origin. Length)]; [attribtStr appendAttributedString:attribtStr_origin];Copy the code

#####10.Mansonry does not use weak references why not circular references

-(NSArray )mas_makeConstraints:(void(^)(MASConstraintMaker ))block {self.translatesAutoresizingMaskIntoConstraints = NO; MASConstraintMaker *constraintMaker = [[MASConstraintMaker alloc] initWithView:self]; block(constraintMaker);return[constraintMaker install]; }Copy the code

This is the same as using self in web requests. Because UIView does not hold a block strongly, the block is just a stack block and does not constitute a condition for circular references. One of the properties of a stack block is that it exits the stack after it finishes executing, and then it gets released. If you look at the mas_makexxx method implementation, you can see that the block is called very quickly and then destroyed out of the stack. There is no circular reference, so you can use self without worry. It will be destroyed after the block is completed and the method will be completed. Therefore, weak will not be required because it will not be quoted all the time. Weak, weak, weak #####11. Jump to multiple levels

      [[_app_ getTabBar] selectTableBarIndex:2];
        [self.navigationController popToRootViewControllerAnimated:NO];
        UINavigationController *selectedNavi = [_app_ getTabBar].selectedViewController;
        
        if (selectedNavi.viewControllers.count >0) {
            
            if([[selectedNavi.viewControllers firstObject] class] == [ProfileViewController class]) { PropertyDetailViewController *propertyDetailVC =[[PropertyDetailViewController alloc]initWithPropertyType:6]; ProfileViewController *ProfileViewController = [selectedNavi.viewControllers firstObject]; [ProfileViewController.navigationController pushViewController:propertyDetailVC animated:NO]; }}Copy the code

#####12. Modification of rich text fonts

  NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:@"I have read and agree to XXXX Merchant Cooperation Service Agreement."];
        [str addAttributes:@{NSForegroundColorAttributeName:[Toolkit getColor:@"507daf"]} range:NSMakeRange(7, 13)];
        _agreenedLabel.attributedText = str;
Copy the code

#####13. Keyboard occlusion problem gesture conflict

- (BOOL) gesturecognizer :(UIGestureRecognizer *) gesturecognizer shouldReceiveTouch:(UITouch *)touch {if(touch.view ! = self.customCollectionView) { [self.view endEditing:YES];return NO;
    }
    return YES;
}
Copy the code

#####14. Keyboard input box limits input and other processing

1. Add event [_phoneTextField addTarget:self Action :@selector(textFieldDidChange:)forControlEvents:UIControlEventEditingChanged]; 2. The processing method - (void) textFieldDidChange: (UITextField at *) textField {UITextRange * selectedRange = textField. MarkedTextRange; UITextPosition *position = [textField positionFromPosition:selectedRange.start offset:0];if(! Position) {/ / not highlight / / 1. The choice of word filter of Chinese characters, letters, Numbers, characters, the self. PhoneTextField. Text = [self filterCharactor: textField. Text withRegex: @"[^ 0-9]." "]; / / 2. Interceptionif(self.phoneTextField.text.length >= 12) { self.phoneTextField.text = [self.phoneTextField.text substringToIndex:11]; }}else{// highlight the selected characters do nothing}} // filter the string of non characters, letters, numbers - (NSString *)filterCharactor:(NSString *)string withRegex:(NSString *) *)regexStr{ NSString *filterText = string; NSError *error = NULL; NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:regexStr options:NSRegularExpressionCaseInsensitive error:&error]; NSString *result = [regex stringByReplacingMatchesInString:filterText options:NSMatchingReportCompletion range:NSMakeRange(0, filterText.length) withTemplate:@""];
    return result;
}

Copy the code

Generics in #####15.oc

Example: - (void)test {
    NSMutableArray<NSString *> *strArray = [NSMutableArray array];
    [strArray addObject:@"aString"];
}
Copy the code

You can declare NSMutableArray with a weak generic constraint. It’s weak generic because the compiler will check for you to see if the data type is correct. If it’s not, you’ll get a warning, but it won’t force an error, and your code will compile.

// If the type is not specified, a warning will be given - (void)test{ NSMutableArray<NSString *> *strArray = [NSMutableArray array]; [strArray addObject: [NSNumber numberWithFloat: 15.0]]. }Copy the code

#####16. Modify UIAlertView to set text alignment left because iphoneSDK is centered by default and does not provide methods to set text alignment interface, in Delegate:

- (void)willPresentAlertView:(UIAlertView *)alertView;
Copy the code

Get the Message control on UIAlertView, which is actually a UILable control, and set its textAlignment property. The code is as follows:

- (void)willPresentAlertView:(UIAlertView *)alertView{
    UIView * view = [alertView.subviews objectAtIndex:2];
    if([view isKindOfClass:[UILabel class]]){ UILabel* label = (UILabel*) view; label.textAlignment = UITextAlignmentLeft; }}Copy the code

Note that Message’s UILable is the third element in alertView.subviews. The first element is a UIImageView(background),UILable(title),UILable(Message),UIButton(Cancel)… (and so on, if any).

6 6s 7 width and 5s output width have been set to the standard mode and disappear

CGRect bounds = [[UIScreen mainScreen] bounds];
 NSString *screenMode = [[UIScreen mainScreen].coordinateSpace description]; CGFloat scale = [[UIScreen mainScreen] scale];
 CGFloat nativeScale = [[UIScreen mainScreen] nativeScale];
 NSLog(@"\n bounds: %@\n screen mode: %@\n scale: %f\n native scale: %f", NSStringFromCGRect(bounds), screenMode, scale, nativeScale);
Copy the code

#####18. Write the local dictionary as the required JSON local file

1. Check whether the current object can be converted to JSON dataif obj can be converted to JSON data, otherwise NO
    BOOL isYes = [NSJSONSerialization isValidJSONObject:dict];
    
    if (isYes) {
        NSLog(@"Convertible");
        
        /* JSON data for obj, or nil if an internal error occurs. The resulting data is a encoded inUTF-8. */ NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict options:0 error:NULL]; // Add the suffix to the file to tell others the current file type. // Note: AFN determines the data type by the file type! If you don't add a type, you may not be able to identify it! It is best to add the file type yourself"/Users/ygkj/Desktop/shopCartTestData.json" atomically:YES];
        
        NSLog(@"% @", [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]);
        
    } else {
        
        NSLog(@"JSON data generation failed, please check data format");
        
    }
Copy the code

#####19. The problem of scrolling trying not to scroll

-(void)viewDidLayoutSubviews
{
    _BaseScore.contentSize = CGSizeMake(SCREEN_WIDTH, xxxx);
}
Copy the code