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