1

I've initialized a QLabelElement, and then later want to update its value. However explicitly setting the .value property on the instance of QLabelElement doesn't update its value. Here is a snippet of what I'm trying to do. The onSelected delegate is executed when the sayHello button is pressed, but the label element isn't updated:

@implementation MyController
{
    QLabelElement *_theLabel;
}

- (id)init
{
    self = [super init];
    QRootElement *root = [[QRootElement alloc] init];
    QSection *section = [[QSection alloc] init];
    _theLabel = [[QLabelElement alloc] initWithTitle:@"The Label" Value:@""];
    QSection *sectionButton = [[QSection alloc] init];
    QButtonElement *sayHello = [[QButtonElement alloc] initWithTitle:@"Say Hello"];

    [sections and controls added to root, etc]

    sayHello.onSelected = ^{
        _theLabel.value = @"Hello has been said"; //<-- this isn't working
    };

    //setting _theLabel.value = @"Hello has been said" here works, but not in the delegate

    self.root = root;

    return self;
}
Amir
  • 9,091
  • 5
  • 34
  • 46

2 Answers2

2

You need to reload the cell for that element after it's loaded. Also, be careful with retain loops, use weak variables:

__weak QLabelElement *weakLabel = _theLabel;
sayHello.onSelected = ^{
    weakLabel.value = @"Hello has been said"; //<-- this isn't working
   [self.quickDialogTableView reloadCellForElements:weakLabel, nil];
};

There's a branch of QD that resolves this automatically, but it's definitely not ready for consumption.

Eduardo Scoz
  • 24,653
  • 6
  • 47
  • 62
1

I do not believe the onSelected event implementation reloads the data being rendered on the screen. There are a couple ways to approach rendering the update:

1) Reload the entire UITableView

- (void)reloadData

Apple Doc - reloadData

2) Reload the data if you know the index path

- (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation

Apple Doc - reloadRowsAtIndexPaths!

Anuj
  • 3,134
  • 13
  • 17