我在收藏视图中有5个按钮。每个按钮都有像nike reebok等品牌标志,它有一个IBAction即按下按钮。 我有一个包含键和值的数组,如
(
{
id=1
brandname=nike
},
{
id=2
brandname=reebok
},
.
.
.
.
)
当我点击集合视图的nike按钮时,它调用按下按钮并将数据存储在数组中只有品牌名称为“nike”
第二件事是,当我第一次穿上那个nike按钮之后,这个按钮保持按下而不是点击两次
如何能够在IBAction方法中匹配条件......
请告诉我,我是ios的新朋友。 - (UICollectionViewCell *)collectionView:(UICollectionView *)cv
cellForItemAtIndexPath: (NSIndexPath *)indexPath
{
UICollectionViewCell *cell=[cv
dequeueReusableCellWithReuseIdentifier:@"cellIdentifier"
forIndexPath:indexPath];
collectionView_button =[UIButton buttonWithType:UIButtonTypeCustom];
collectionView_button=[[UIButton alloc]initWithFrame:CGRectMake(1, 1, 98, 48) ];
collectionView_button.tag = indexPath.item;
NSString *imageNames = [NSString stringWithFormat:@"%@",[arr_ButtonImg
objectAtIndex:indexPath.item]];
[collectionView_button setBackgroundImage:[UIImage imageNamed:imageNames]
forState:UIControlStateNormal];
[collectionView_button addTarget:self action:@selector(buttonPressed:)
forControlEvents:UIControlEventTouchUpInside];
[cell addSubview:collectionView_button];
}
// ibaction
-(IBAction)buttonPressed:(UIButton *)sender
{
int c=0;
for (int i=0; i<[Temp_arr_JsonData count]; i++)
{
NSString *str_brandname = [[Temp_arr_JsonData objectAtIndex: i]
valueForKey:@"storebrand"];
NSLog(@"%@",str_brandname);
NSObject *myNewObject = [[NSObject alloc] init];
if ([str_brandname isEqualToString:@"Nike"])
{
NSLog(@"Data matched");
c++;
myNewObject=[Temp_arr_JsonData objectAtIndex:i];
[temparray addObject:myNewObject];
}
}
arr_JsonData=temparray;
[self.tableView reloadData];
[sender setSelected:YES];
}
当我点击Reebok按钮时,它会在表格中显示Nike和Reebok数据......我只想要ibaction中的条件