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類型就是實現(xiàn)方法
void(*imp)(id, SEL) = (typeof(imp))[self methodForSelector:selectors[buttonIndex]];
imp(self, selectors[buttonIndex]);
}
}