onegray / RadioButton-ios

Lightweight RadioButton class for iOS
MIT License
377 stars 68 forks source link

RadioButton TabbleViewCell #4

Closed haidershahzad closed 9 years ago

haidershahzad commented 9 years ago

Hello, Im trying to use your radio-button api into one of my project with tableview, data is loaded from the web server which is done. The problem is when i select any option after scroll its reset to its default value, i almost stuck in it from a week please help me out here. below is my code.


if ([module isEqualToString:@"RADIO"]) {

    static NSString *CellIdentifier = @"radiocell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleDefault;
    cell.backgroundColor = [UIColor clearColor];
    cell.backgroundView = nil;

    NSMutableArray* buttons = [[NSMutableArray alloc] init];
    CGRect btnRect = CGRectMake(25, 5, 300, 30);
    for (NSString* optionTitle in category) {

        RadioButton* btn = [[RadioButton alloc] initWithFrame:btnRect];
        [btn addTarget:self action:@selector(onRadioButtonValueChanged:) forControlEvents:UIControlEventValueChanged];
        btnRect.origin.y += 40;
        [btn setTag:indexPath.row];
        [btn setTitle:optionTitle forState:UIControlStateNormal];
        [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        btn.titleLabel.font = [UIFont fontWithName:@"HelveticaNeue-Regular" size:15];
        [btn setImage:[UIImage imageNamed:@"unchecked.png"] forState:UIControlStateNormal];
        [btn setImage:[UIImage imageNamed:@"checked.png"] forState:UIControlStateSelected];
        btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        btn.titleEdgeInsets = UIEdgeInsetsMake(0, 6, 0, 0);
        [cell.contentView addSubview:btn];
        [buttons addObject:btn];
    }
    [buttons[0] setGroupButtons:buttons];
    [buttons[0] isButtonSelected:YES];

    return cell;
onegray commented 9 years ago

Its not a right place for such questions. Use stackoverflow.