//主要知识点:
当创建多个Button时,而又每个Button触发的事件又是不同,那么可以通过
SEL selector = NSSelectorFromString(methods[i]);//转换
例:
NSArray *titles =@[@"SAX解析",@"Dom解析第一种方式",@"Dom解析第二种方式",@"系统解析",@"字符串解析",@"数组解析",@"字典解析",@"Data解析"];
NSArray *methods = @[@"handleSAX:",@"handleDomBtn1:",@"handleDomBtn2:",@"handleSystemJSON:",@"handleStrBtn:",@"handleArrBtn:",@"handleDicBtn:",@"handleDataBtn:"];
CGFloat height = 70;
for (int i = 0; i < 8; i++) {
UIButton *SAXBtn = [UIButtonbuttonWithType:UIButtonTypeSystem];
SAXBtn.frame =CGRectMake(60, height, 200, 30);
SAXBtn.backgroundColor = [UIColorgreenColor];
[SAXBtnsetTitle:titles[i] forState:UIControlStateNormal];
SEL selector =NSSelectorFromString(methods[i]);
[SAXBtnaddTarget:selfaction:selectorforControlEvents:UIControlEventTouchUpInside];
[self.viewaddSubview:SAXBtn];
height +=40;
}
原文地址:http://blog.csdn.net/mhtios/article/details/39203179