我初始化了一个QLabelElement,后来想要更新它的值。但是,在QLabelElement实例上显式设置.value属性不会更新其值。这是我正在尝试做的事情的片段。按下sayHello按钮时会执行onSelected委托,但标签元素不会更新:
@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; }
答案 0 :(得分:2)
您需要在加载后重新加载该元素的单元格。另外,请注意保留循环,使用弱变量:
__weak QLabelElement *weakLabel = _theLabel;
sayHello.onSelected = ^{
weakLabel.value = @"Hello has been said"; //<-- this isn't working
[self.quickDialogTableView reloadCellForElements:weakLabel, nil];
};
QD的一个分支可以自动解决这个问题,但它绝对不能用于消费。
答案 1 :(得分:1)
我不相信onSelected事件实现会重新加载屏幕上呈现的数据。有几种方法可以实现更新:
1)重新加载整个UITableView
- (void)reloadData
2)如果您知道索引路径
,请重新加载数据- (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation