有没有办法检查我的tableview刚完成滚动?table.isDragging并且table.isDecelerating是我能找到的唯一两种方法.当tableview完成滚动时,我不确定如何预测或得到通知.
如果tableView正在滚动,我可以以某种方式使用计时器来检查每一秒吗?
我一直在尝试编写一个自定义模板标签来简单地缩短链接,我附上了代码和错误,我一直在下面.我试着查看Django提供的文档,但看不出我做错了什么.
我将模板标签放在以下布局中:
scribbler/
models.py
templatetags/
__init__.py
shortenlink.py
views.py
Run Code Online (Sandbox Code Playgroud)
我写的自定义标记文件:
from django import template
from django.conf import settings
from urllib import urlencode
from urllib2 import urlopen
register = template.Library()
@register.simple_tag
def bitlyshort(the_url):
endpoint = 'https://api-ssl.bitly.com/v3/shorten?access_token={0}&longUrl={1}&format=txt'
req = urlencode(endpoint.format(settings.ACCESS_KEY, the_url))
return urlopen(req).read()
Run Code Online (Sandbox Code Playgroud)
使用模板标记的模板的一部分:
{% load shortenlink %}
<p>{{ bitlyshort "http://www.google.com" }}</p>
Run Code Online (Sandbox Code Playgroud)
TemplateSyntaxError at /user/sankaetp/
Could not parse the remainder: ' "http://www.google.com"' from 'bitlyshort "http://www.google.com"'
Request Method: GET
Request URL: http://localhost:8000/user/sankaetp/
Django Version: 1.4.1
Exception Type: TemplateSyntaxError
Exception Value:
Could …Run Code Online (Sandbox Code Playgroud) 我只是想知道Django是否有办法从一堆文本中检测URL然后自动缩短它们.我知道我可以使用urlize来检测网址,但我不确定我是否可以使用点滴或其他东西来缩短链接.
用javascript而不是python来完成这个任务会更好吗?如果是这样的话我该怎么办呢?
我正在尝试使用uiimage-from-animated-gif将一些GIF加载到我的UITableView单元格中.但问题是,每当我尝试从我的Cache加载图像时,单元格在滚动之前会暂停一点.
这是我正在使用的代码
postGif = (UIImageView *)[cell viewWithTag:104];
if ([[ImageCache sharedImageCache] DoesExist:post[@"gif"]] == true)
{
image = [[ImageCache sharedImageCache] GetImage:post[@"gif"]];
postGif.image = [UIImage animatedImageWithAnimatedGIFData:image];
}else
{
dispatch_queue_t backgroundQueue = dispatch_queue_create("cacheImage", 0);
dispatch_async(backgroundQueue, ^{
NSData *imageData = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString:post[@"gif"]]];
dispatch_async(dispatch_get_main_queue(), ^{
// Add the image to the cache
[[ImageCache sharedImageCache] AddImage:post[@"gif"] image:imageData];
NSIndexPath* ind = [NSIndexPath indexPathForRow:0 inSection:indexPath.section];
[self.feedTableView beginUpdates];
[self.feedTableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:ind] withRowAnimation:UITableViewRowAnimationNone];
[self.feedTableView endUpdates];
});
});
}
postGif.layer.cornerRadius = 2.0;
postGif.layer.masksToBounds = YES;
[cell.contentView addSubview:postGif]; …Run Code Online (Sandbox Code Playgroud) django ×2
ios ×2
uitableview ×2
javascript ×1
objective-c ×1
python ×1
uiimageview ×1
uiscrollview ×1