У меня есть пользовательская ячейка таблицы с кнопкой и меткой. Значение метки извлекается из NSMutableArray и по умолчанию скрыта метка. При нажатии кнопки я хочу отобразить ярлык той же ячейки. Заранее спасибо.В пользовательском UITableViewCell Hide/Unhide 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;
}
}
напишите свой код, что вы пробовали? –