id列表 eg:["1","2"]//字符串拼接
声明
@property (strong,nonatomic) NSMutableString *String;
Bool isBtn = NO;
方法
-(void)setimage:(UIButton *)ban{
//判断长度 拼接中括号 []
if (self. String.length == 0) {
[self String appendString:[NSString stringWithFormat:@"[]"]];
}
if( isBtn ==NO){ //取消数值
isBtn =YES;
//第一个值是多少
int fistNum= [[self. String substringWithRange:NSMakeRange(2,2)] intValue];
//是否相等
if ( istNum == btn.tag) {
if (self.StrToAvc.length == 6) {//判断是否只有一个数值
NSRange range = [String rangeOfString:[NSString stringWithFormat: @"\"%ld\"",(long)btn.tag]];
[String deleteCharactersInRange:range];
}else{
NSRange range = [String rangeOfString:[NSString stringWithFormat: @"\"%ld\",",(long)btn.tag]];
[self.StrToAvc deleteCharactersInRange:range];
}
}else{
NSRange range = [self.StrToAvc rangeOfString:[NSString stringWithFormat: @",\"%ld\"",(long)btn.tag]];
[self.StrToAvc deleteCharactersInRange:range];
}
}else{//增加数值
isBtn=NO;
if (self. String.length == 2) {
[self. String insertString:[NSString stringWithFormat: @"\"%ld\"",(long)btn.tag] atIndex:self. String.length-1];
}else{
// [self. String appendString:[NSString stringWithFormat: @",\"%ld\"",(long)btn.tag]];
[self. String insertString:[NSString stringWithFormat: @",\"%ld\"",(long)btn.tag] atIndex:self. String.length-1];
}
}
}