cell裏面點擊不同的button顏色變化:
- (IBAction)SelectColor:(UIButton *)sender {
for (UIView *view in [self.contentView subviews]) {if ([view isMemberOfClass:[UIButton class]]) {
UIButton *button=(UIButton*)view;
if (button.tag ==sender.tag) {
button.layer.borderWidth=0.5;
button.layer.borderColor=[UIColor redColor].CGColor;
}
else
{
button.layer.borderWidth=0.5;
button.layer.borderColor=[UIColor lightGrayColor].CGColor;
}
}
}
}
網絡請求:
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSString *strURL =[NSString stringWithFormat:@"%@具體方法名?參數1=%@",公共部分,@"值"];
NSString *str = [strURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *url = [NSURL URLWithString:str];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
if (error != nil){
[AppHelper showMessage:[NSString stringWithFormat:@"%@",error]];
}
else if ([data length] >0 && error == nil){
NSString *result = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"獲得數據=%@",result);
}
else if ([data length] == 0 && error == nil){
[AppHelper showMessage:@"沒有數據"];
}
});
}];
});
異步線程:
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
NSDictionary* dic = [[UtilityManager shareMgr] server_getVIPPriceWithDic:param];
NSLog(@"psc返回結果 =======> app_notify_url = %@",dic);
dispatch_async(dispatch_get_main_queue(), ^{
[hud setHidden:YES];
if (dic) {
self.priceDict = (NSMutableDictionary *)dic;
[self.tableView reloadData];
}else{
[CTCommon addAlertWithTitle:@"*******"];
}
});
});
1.url編碼
ios中http請求遇到漢字的時候,需要轉化成UTF-8,用到的方法是:
NSString * encodingString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
2.url解碼
請求後,返回的數據,如何顯示的是這樣的格式:%3A%2F%2F,此時需要我們進行UTF-8解碼,用到的方法是:
NSString *str = [model.album_name stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];