• iOS 开发小常识 开发笔记


    一   自定义push方法

    /*  参数说明             

     *  controllerName : push的目标页 例:@“testcontroll”    ---注意不带.h

     *  isNibPage     : 目标页是否带 xib 文件

     *  setHideTabBar : 当前页是否隐藏 tabBar      -----注意 是当前页 非目标页

     *  setDelegate   : 设置委托

     */

    - (void)pushNewViewController:(NSString *)controllerName isNibPage:(BOOL) _isNib setHideTabBar:(BOOL) _bool setDelegate:(BOOL) _setdelegate{

        

        if (controllerName.length <= 0) {

            return;

        }

        

        Class   class_Page = NSClassFromString((NSString *)controllerName);

        id viewCtrl_Page = _isNib ? [[class_Page alloc] initWithNibName:controllerName bundle:nil]

        : [[class_Page alloc] init];

        

        if (_setdelegate) { [viewCtrl_Page setDelegate:self]; }

        if (!m_Params)    { m_Params = [[NSMutableDictionaryalloc]init]; }

        

        [m_Params setValue:_bool == YES ? @"1" : @"0" forKey:@"HideTabBar"];

        [viewCtrl_Page setM_Params:[m_Params retain]];

        

        if (isLoginPage) {

            if ([GlobalisUserLogin]) {

                [self.navigationControllerpushViewController:viewCtrl_Page animated:YES];

            }

            else{

                [selfshowLoginController];

            }

        }

        else

            [self.navigationControllerpushViewController:viewCtrl_Page animated:YES];

        

        [viewCtrl_Page release];

        

        if (m_Params) {

            [m_Params release];

        }

    }

    二       根据TableView里的button获取父级UITableViewCell

       1.   通过对像的父级查找

             UIButton *btn_checkBox = (UIButton *)sender;

               UITableViewCell * cell = (UITableViewCell *)[btn_checkBox superview];

               NSIndexPath* indexPath = [m_tableViewindexPathForCell:cell];

       2.   通过点击座标

    // 检查用户点击按钮时的位置,并转发事件到对应的accessory tapped事件
    - (void)btnClicked:(id)sender event:(id)event
    {
    NSSet *touches = [event allTouches];
    UITouch *touch = [touches anyObject];
    CGPoint currentTouchPosition = [touch locationInView:self.tableView];
    NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:currentTouchPosition];
    if(indexPath != nil)
    {
    [self tableView:self.tableView accessoryButtonTappedForRowWithIndexPath:indexPath];
    }
    }

    三  常常要算一段文字的长度和高度。下面这段代码可以帮到你

    CGSize  fontsize = [tmpCoupon.couponDescsizeWithFont:[UIFontboldSystemFontOfSize:13] constrainedToSize:CGSizeMake(162, MAXFLOAT) lineBreakMode:NSLineBreakByWordWrapping];

      // 计算文本的大小  ios7.0

        CGSize textSize = [textViewTemple.text boundingRectWithSize:CGSizeMake(self.imagewidth, MAXFLOAT)                                                         options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading // 文本绘制时的附加选项

                                                         attributes:dic  context:nil].size;

    四  文本编辑的时候键盘档住页面,下面代码自动收缩

    - (void)textFieldDidBeginEditing:(UITextField *)textField{

      CGRect frame = textField.frame;

      int offset = frame.origin.y + 32 - (self.view.frame.size.height - 216.0-10);

      NSTimeInterval animationDuration = 0.30f;

         [UIView beginAnimations:@"ResizeForKeyBoard" context:nil];

    [UIView setAnimationDuration:animationDuration];
    float width = self.view.frame.size.width;
    float height = self.view.frame.size.height;
    if(offset > 0){
    CGRect rect = CGRectMake(0.0f, -offset,width,height);
    self.view.frame = rect;
    }
    [UIView commitAnimations];

    }

    - (BOOL)textFieldShouldReturn:(UITextField *)textField{
    NSTimeInterval animationDuration = 0.30f;
    [UIView beginAnimations:@"ResizeForKeyboard" context:nil];
    [UIView setAnimationDuration:animationDuration];
    CGRect rect = CGRectMake(0.0f, 0.0f, self.view.frame.size.width, self.view.frame.size.height);
    self.view.frame = rect;
    [UIView commitAnimations];

    [textField resignFirstResponder];
    return YES;

    // 十六进制设置alpha值

    + (UIColor *)convertHexToRGB:(NSString *)hexString alpha:(CGFloat)alpha {

        NSString *str;

        if ([hexString hasPrefix:@"0x"] || [hexString hasPrefix:@"0X"]) {

            str=[[NSString alloc] initWithFormat:@"%@",hexString];

        }else {

            str=[[NSString alloc] initWithFormat:@"0x%@",hexString];

        }

        int rgb;

        sscanf([str cStringUsingEncoding:NSUTF8StringEncoding], "%i", &rgb);

        [str release];

        int red=rgb/(256*256)%256;

        int green=rgb/256%256;

        int blue=rgb%256;

        UIColor *color=[UIColor colorWithRed:red/255.0 green:green/255.0 blue:blue/255.0 alpha:alpha];

        return color;

    }

    五  .  数组排序

           NSSortDescriptor * sortDescriptor = [[NSSortDescriptoralloc] initWithKey:@"createTime"ascending:NO];

           [arrMsgListsortUsingDescriptors:[NSArrayarrayWithObject:sortDescriptor]];

  • 相关阅读:
    springboot和springcloud的区别是什么?【杭州多测师】【杭州多测师_王sir】
    最常见的Java面试题【杭州多测师_王sir】【杭州多测师】
    Excel xlsx file not supported两种解决办法【杭州多测师】【杭州多测师_王sir】
    spring boot的全局异常处理是怎么做的呢?【杭州多测师】【杭州多测师_王sir】
    查看sap版本
    SAP移动类型/Movement Type
    预留/Reservation
    预留与锁库
    Java代做编程辅导:CS415 Blackjack
    Python主题建模LDA模型、tSNE 降维聚类、词云可视化文本挖掘新闻组数据集|附代码数据
  • 原文地址:https://www.cnblogs.com/yswdarren/p/3554436.html
Copyright © 2020-2023  润新知