记录开发遇到的两个问题,以及解决方案
1、 UITableViewCell的选中问题
总所周知,cell的选中样式有三种,UITableViewCellSelectionStyleNone、UITableViewCellSelectionStyleGray、
UITableViewCellSelectionStyleBlue。
另外,UITableViewCellSelectionStyleBlue这也属性在iOS7以后已经不起作用了。
下面这种情况下,cell在选中的时候,会把子视图的背景颜色换成默认的淡蓝色。
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
return UITableViewCellEditingStyleDelete | UITableViewCellEditingStyleInsert;
}
这种cell多选模式下,如果设置了cell的选中样式为None,那我们就无法对cell进行选择了。
这个时候,想即设置了cell的选中样式,又不会被选中后改变背景颜色,就可以重写下面的两个方法。把被改变颜色的子视图设置为你想要的效果。
- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated {
[super setHighlighted:highlighted animated:animated];
self.progressView.centerLabel.backgroundColor = [UIColor clearColor];
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
self.progressView.centerLabel.backgroundColor = [UIColor clearColor];
}
2、URL的编码问题
对于URL里包含中文的,一般我们会采取下面这种方式进行转码。
NSString *routing = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
但是,对于中文已经被转码过的,里面包含了转义字符。如果我们再次用这种方式转码,就会出问题。
所以我们应该对包含中文字符和不包含中文字符的URL进行区分,下面的一个方法很好的解决了这个问题。
NSString *encodedString = (NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,
(CFStringRef)self.videoUrl,
(CFStringRef)@"!$&'()*+,-./:;=?@_~%#[]",
NULL,
kCFStringEncodingUTF8));