OC小结

作者: Jackson_Z | 来源:发表于2017-04-14 18:37 被阅读25次

禁止第三方输入键盘

//禁止第三方输入键盘
- (BOOL)application:(UIApplication *)application shouldAllowExtensionPointIdentifier:(NSString *)extensionPointIdentifier {
    return NO;
}

行数算法

//行数
NSInteger row = (self.btnArr.count + colNum - 1) / colNum;

九宫格算法

-(void)layoutSubviews{
    [super layoutSubviews];
    //设置按钮的frame值
    //计算处在哪行哪列
    for (int i = 0; i < self.btnArr.count; ++i) {
        
        NSInteger col = i % colNum;
        NSInteger row = i / colNum;
        
        CGFloat btnX = padding + col * (tangButtonW + margin);
        CGFloat btnY = 44 + padding + row * (tangButtonH + margin);
        //设置按钮的frame值
        UIButton *btn = self.btnArr[i];
        btn.frame = CGRectMake(btnX, btnY, tangButtonW, tangButtonH);
    }
}

处理连点

[[self class] cancelPreviousPerformRequestsWithTarget:self selector:@selector(todoSomething:) object:btn];
[self performSelector:@selector(todoSomething:) withObject:btn afterDelay:0.2f];

IMP类型(就是实现方法) 来源:UITableView-FDTemplateLayoutCell-master

- (IBAction)rightNavigationItemAction:(id)sender {
    [[[UIActionSheet alloc]
      initWithTitle:@"Actions"
      delegate:self
      cancelButtonTitle:@"Cancel"
      destructiveButtonTitle:nil
      otherButtonTitles:
      @"Insert a row",
      @"Insert a section",
      @"Delete a section", nil]
     showInView:self.view];
}

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    SEL selectors[] = {
        @selector(insertRow),
        @selector(insertSection),
        @selector(deleteSection)
    };

    if (buttonIndex < sizeof(selectors) / sizeof(SEL)) {
        //定义IMP类型,IMP类型就是实现方法
        void(*imp)(id, SEL) = (typeof(imp))[self methodForSelector:selectors[buttonIndex]];
        imp(self, selectors[buttonIndex]);
    }
}

- (FDFeedEntity *)randomEntity {
    NSUInteger randomNumber = arc4random_uniform((int32_t)self.prototypeEntitiesFromJSON.count);
    FDFeedEntity *randomEntity = self.prototypeEntitiesFromJSON[randomNumber];
    return randomEntity;
}

- (void)insertRow {
    if (self.feedEntitySections.count == 0) {
        [self insertSection];
    } else {
        [self.feedEntitySections[0] insertObject:self.randomEntity atIndex:0];
        NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
        [self.tableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
    }
}

- (void)insertSection {
    [self.feedEntitySections insertObject:@[self.randomEntity].mutableCopy atIndex:0];
    [self.tableView insertSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationAutomatic];
}

- (void)deleteSection {
    if (self.feedEntitySections.count > 0) {
        [self.feedEntitySections removeObjectAtIndex:0];
        [self.tableView deleteSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationAutomatic];
    }
}

相关文章

  • swift基础小结1

    swift基础小结 for 循环OC与Swift对比 While循环与downhill循环 OC与swift使用的...

  • OC小结

    禁止第三方输入键盘 行数算法 九宫格算法 处理连点 IMP类型(就是实现方法) 来源:UITableView-FD...

  • OC:Masonry小结

    对于在ViewController内,使用mas_XXXLayoutGuide对于在View内,推荐使用mas_X...

  • OC:Layer小结

    线和多边形是一些简单的形状,我们可以用moveToPoint:或者addLineToPoint:方法去构建。方法m...

  • protobuf 集成小结OC

    第一步、配置环境(重要)1、安装 protobuf , 注意: protobuf必须是最新版本,如果已经安装了, ...

  • swift-循环

    循环 OC风格的 for Swift风格的 for 阶段性小结Swift 中使用 in 关键字标示循环的范围0.....

  • 3.Swift-循环

    OC风格的 for Swift风格的 for 阶段性小结Swift 中使用 in 关键字标示循环的范围0..<10...

  • OC关联对象小结(一)

    OC关联对象小结(一) 使用场景 为现有的类添加属性,变量 在Objective-C中可以通过Category给一...

  • OC - runtime常见用法小结

    消息机制 - 调用私有方法 OC的runtime特性,使其没有严格意义上的私有方法。 方法交换 很多时候,我们想要...

  • OC 面试题小结

    如何传过来的obj对象恰好 就是原来的这个对象 当我们对这个对象进行release 操作时 实际上也是对 传递进来...

网友评论

      本文标题:OC小结

      本文链接:https://www.haomeiwen.com/subject/ijkgattx.html