美文网首页
#iOS Dev.#Objective-C 使用小结

#iOS Dev.#Objective-C 使用小结

作者: HeminWon | 来源:发表于2017-05-18 19:42 被阅读21次

SEL和IMP类型的应用来源:UITableView-FDTemplateLayoutCell-master

- (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]);
    }
}

相关文章

网友评论

      本文标题:#iOS Dev.#Objective-C 使用小结

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