我有两个UITableViewControllers,我在它们之间使用故事板进行区分.
在prepareForSegue:sender:,第一个VC从Web服务获取NSArray,并使用下载的数据设置目标VC的模型.我把下载部分放入一个dispatch_queue_t所以它将异步运行而不是阻止UI线程.我想点击一个表格单元格,让UIActivityIndicatorView开始旋转,下载照片,下载照片时,停止微调器并继续使用segue.
在第一个UITableViewController我有一个prepareForSegue:sender:方法:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"SelectPlace"]) {
NSIndexPath *indexPath = [self.tableView indexPathForCell:sender];
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc]
initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
[spinner startAnimating];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:spinner];
__block NSArray *photos = [[NSMutableArray alloc] init];
dispatch_queue_t downloadQueue = dispatch_queue_create("flickr download", NULL);
dispatch_async(downloadQueue, ^{
photos = [FlickrFetcher photosInPlace:[self.places objectAtIndex:indexPath.row] maxResults:50];
});
dispatch_release(downloadQueue);
[spinner stopAnimating];
[segue.destinationViewController setPhotos:photos withTitle:[[sender textLabel] text]];
}
}
Run Code Online (Sandbox Code Playgroud)
现在它立即执行segue而不显示微调器或等待下载完成.
如何在不阻塞主线程的情况下异步下载数据以准备目标视图,还能不立即进行segueing?
我正在使用CSS-Tricks中的代码来获取当前使用JavaScript的旋转变换(在CSS中).
JavaScript函数:
function getCurrentRotation( elid ) {
var el = document.getElementById(elid);
var st = window.getComputedStyle(el, null);
var tr = st.getPropertyValue("-webkit-transform") ||
st.getPropertyValue("-moz-transform") ||
st.getPropertyValue("-ms-transform") ||
st.getPropertyValue("-o-transform") ||
st.getPropertyValue("transform") ||
"fail...";
if( tr !== "none") {
console.log('Matrix: ' + tr);
var values = tr.split('(')[1];
values = values.split(')')[0];
values = values.split(',');
var a = values[0];
var b = values[1];
var c = values[2];
var d = values[3];
var scale = Math.sqrt(a*a + b*b);
// arc sin, convert from radians …Run Code Online (Sandbox Code Playgroud) 我正在编写一个WordPress插件,其中一个功能是删除重复的空格.
我的代码看起来像这样:
return preg_replace('/\s\s+/u', ' ', $text, -1, $count);
Run Code Online (Sandbox Code Playgroud)
我不明白为什么我需要u
修饰符.我见过其他使用preg_replace但不需要为Unicode修改它的插件.我相信我有一个WordPress的默认安装.
如果没有修饰符,代码将使用Unicode替换字形而不是空格替换所有空格.
使用u修饰符,我没有得到字形,并且它不会替换所有空格.
下面的每个空间都有1-10个空格.正则表达式仅从每个组中移除空间.
之前:
This sentence has extra space. This doesn’t. Extra space, Lots of extra space.
Run Code Online (Sandbox Code Playgroud)
后:
This sentence has extra space. This doesn’t. Extra space, Lots of extra space.
Run Code Online (Sandbox Code Playgroud)
$count = 9
如何让正则表达式替换整个匹配的空间?
$new_text = preg_replace('/\s\s+/', ' ', $text, -1, $count);
Run Code Online (Sandbox Code Playgroud)
它只在我在wordpress插件中使用它时才会中断.我在过滤器中使用此功能:
function jje_test( $text ) {
$new_text = preg_replace('/\s\s+/', ' ', $text, -1, $count);
echo "Count: $count";
return $new_text;
} …Run Code Online (Sandbox Code Playgroud) asynchronous ×1
css ×1
css3 ×1
ios ×1
ios5 ×1
javascript ×1
php ×1
regex ×1
transform ×1
wordpress ×1