- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
示例:
[query findObjectsInBackgroundWithBlock:^(NSArray *favObjects, NSError *error) {
for (PFObject *favObject in favObjects) {
dispatch_async(dispatch_get_main_queue(), ^{
[cell setSizeLabel:[_arrayOfSizes objectAtIndex:[[favObject valueForKey:@"size"] integerValue]]];
[[cell sizeDropDownButton] setTitle:[cell sizeLabel] forState:UIControlStateNormal];
});
if ([[[cell currentObject] valueForKey:@"alternativeColour"] boolValue]) {
// Colours are stored in db on parse as numbers, I use array below to determine which colour is being red back by valueForkey below
dispatch_async(dispatch_get_main_queue(), ^{
[cell setColourLabel:[_arrayOfColours objectAtIndex:[[favObject valueForKey:@"colour"] integerValue]]];
[[cell colourDropDownButton] setTitle:[cell colourLabel] forState:UIControlStateNormal];
});
}
[[cell priceLabelSpinner] stopAnimating];
[[cell titleLabelSpinner] stopAnimating];
[[cell sizeDropDownButton] setHidden:NO];
[[cell colourDropDownButton] setHidden:NO];
}
}];
您可以看到我正在主队列上设置按钮标签标题。但是在下面,我将停止在后台队列上旋转以及取消隐藏按钮。这是正确的吗?
最佳答案
任何可能导致您查看更改的东西都应该从主线程调用:
Manipulations to your application’s user interface must occur on the main thread. Thus, you should always call the methods of the UIView class from code running in the main thread of your application. The only time this may not be strictly necessary is when creating the view object itself but all other manipulations should occur on the main thread.
因此,考虑到 Apple 的建议,您应该将代码重写为:
[query findObjectsInBackgroundWithBlock:^(NSArray *favObjects, NSError *error) {
for (PFObject *favObject in favObjects) {
dispatch_async(dispatch_get_main_queue(), ^{
[cell setSizeLabel:[_arrayOfSizes objectAtIndex:[[favObject valueForKey:@"size"] integerValue]]];
[[cell sizeDropDownButton] setTitle:[cell sizeLabel] forState:UIControlStateNormal];
});
if ([[[cell currentObject] valueForKey:@"alternativeColour"] boolValue]) {
// Colours are stored in db on parse as numbers, I use array below to determine which colour is being red back by valueForkey below
dispatch_async(dispatch_get_main_queue(), ^{
[cell setColourLabel:[_arrayOfColours objectAtIndex:[[favObject valueForKey:@"colour"] integerValue]]];
[[cell colourDropDownButton] setTitle:[cell colourLabel] forState:UIControlStateNormal];
});
}
dispatch_async(dispatch_get_main_queue(), ^{
[[cell priceLabelSpinner] stopAnimating];
[[cell titleLabelSpinner] stopAnimating];
[[cell sizeDropDownButton] setHidden:NO];
[[cell colourDropDownButton] setHidden:NO];
});
}
}];
关于ios - 我应该在主线程上启动和停止 UIActivityIndicator 实例吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24714183/
有人可以向我澄清主线 DHT 规范中的声明吗? Upon inserting the first node into its routing table and when starting up th
我正在尝试使用 USB 小工具驱动程序使嵌入式设备作为 MTP 设备工作。 我知道 Android 从大容量存储设备切换到 MTP 设备已经有一段时间了,并且找到了 source code for M
我是一名优秀的程序员,十分优秀!