我有一個帶有按鈕和標籤的自定義表格視圖單元格。 標籤值是從NSMutableArray中獲取的,默認情況下標籤是隱藏的。點擊按鈕時,我想取消隱藏同一個單元格的標籤。提前致謝。在自定義UITableViewCell按鈕上隱藏/取消隱藏UILabel點擊
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
selCell = [tableView dequeueReusableCellWithIdentifier:@"beautyIdentifier"];
if (selCell == nil) {
selCell = [[MDTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"beautyIdentifier"] ;
}
selCell.backgroundColor=[UIColor colorWithRed:0.878 green:0.878 blue:0.878 alpha:1];
NSObject *labelData=[[reqSubcat objectAtIndex:indexPath.row] objectForKey:@"subcategoryName"];
NSString *label=[NSString stringWithFormat:@"%@",labelData];
//Check Button
checkButton=[[UIButton alloc] init];
[checkButton setFrame:CGRectMake(20,25,30, 30)];
checkButton.layer.cornerRadius = checkButton.frame.size.width /2;
checkButton.clipsToBounds = YES;
checkButton.layer.borderColor = [UIColor lightGrayColor].CGColor;
checkButton.layer.borderWidth = 1.f;
[checkButton addTarget:self action:@selector(checkBox:) forControlEvents:UIControlEventTouchUpInside];
[checkButton setTitle:label forState:UIControlStateNormal];
[checkButton setTitleColor:[UIColor clearColor] forState:UIControlStateNormal];
checkButton.tag=indexPath.row;
[selCell addSubview:checkButton];
NSString *cost=[NSString stringWithFormat:@"₹ %@",[costArray objectAtIndex:indexPath.row]];
CGSize stringsize1 = [cost sizeWithAttributes:@{NSFontAttributeName:
[UIFont systemFontOfSize:40.0f]}];
costLabel=[[UILabel alloc] init];
[costLabel setText:cost];
[costLabel setFrame:CGRectMake(250,20,stringsize1.width, 40)];
costLabel.font=[UIFont fontWithName:@"Futura" size:25];
costLabel.textColor=[UIColor colorWithRed:0.153 green:0.239 blue:0.294 alpha:1];
costLabel.tag=indexPath.row;
costLabel.hidden=NO;
[selCell.contentView addSubview:costLabel];
}
- (void)checkBox:(UIButton *)sender
{
// [email protected]"";
NSLog(@"%@",resetTitle);
NSLog(@"%ld",(long)sender.tag);
if ([sender.titleLabel.text isEqualToString:@"✓"])
{
sender.backgroundColor=[UIColor clearColor] ;
[sender setTitle:resetTitle forState:UIControlStateNormal];
[sender setTitleColor:[UIColor clearColor] forState:UIControlStateNormal];
sender.layer.borderColor = [UIColor lightGrayColor].CGColor;
}
else
{
resetTitle=sender.titleLabel.text;
NSLog(@"%@",resetTitle);
sender.backgroundColor=[UIColor colorWithRed:1 green:0.839 blue:0.314 alpha:1] ;
[sender setTitle:@"✓" forState:UIControlStateNormal];
[sender.titleLabel setFont:[UIFont fontWithName:@"Futura" size:25]];
[sender setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
sender.layer.borderColor = [UIColor clearColor].CGColor;
}
}
發佈你的代碼,你試過了什麼? –