Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/99.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios Xcode中的XML图像加载问题?_Ios_Xcode_Uiimage - Fatal编程技术网

Ios Xcode中的XML图像加载问题?

Ios Xcode中的XML图像加载问题?,ios,xcode,uiimage,Ios,Xcode,Uiimage,在我通过XML解析器显示新闻的应用程序中,问题是在我的XML url中,很少有图像是用阿拉伯语命名的,这些图像正在加载,如果是用英语命名的(例如dsc5804.jpg),则显示效果很好,如果是用阿拉伯语命名的(例如:20%20%20%20%20%20%20%它没有显示,我不确定的问题与图像格式,或从我的代码或其他任何可以告诉我的解决方案,请 你也可以在这里看到我的屏幕截图 图像url链接 这是我的NewsViewController.m #import "NewsViewController.h

在我通过XML解析器显示新闻的应用程序中,问题是在我的XML url中,很少有图像是用阿拉伯语命名的,这些图像正在加载,如果是用英语命名的(例如dsc5804.jpg),则显示效果很好,如果是用阿拉伯语命名的(例如:20%20%20%20%20%20%20%它没有显示,我不确定的问题与图像格式,或从我的代码或其他任何可以告诉我的解决方案,请

你也可以在这里看到我的屏幕截图

图像url链接

这是我的NewsViewController.m

#import "NewsViewController.h"
#import "NewsTableViewCell.h"
#import "NewDetailsViewController.h"
#import <SDWebImage/UIImageView+WebCache.h>
#import "SearchVC.h"
@interface NewsViewController ()
{
    NSString *temString;
    NSMutableString *strTemp;
    BOOL isDateSearch;
}

@end

@implementation NewsViewController
@synthesize arrImages;
@synthesize TittleOne;
@synthesize TittleTwo;
@synthesize TittleThree;
@synthesize datepicker;
@synthesize PickerContainer;
@synthesize datepickerTittle;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

#pragma mark - View Life Cycle
- (void)viewDidLoad
{
    UIActivityIndicatorView *spinnerView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];

    [super viewDidLoad];
    [TittleOne setFont: [UIFont fontWithName:@"GEEast-ExtraBold" size:12]];
    [TittleTwo setFont: [UIFont fontWithName:@"GEEast-ExtraBold" size:10]];
    [TittleThree setFont: [UIFont fontWithName:@"GEEast-ExtraBold" size:10]];
    // [[UIColor redColor] set];
    [datepickerTittle setFont:[UIFont fontWithName:@"GEEast-ExtraBold" size:12]];
    // [datepickerTittle.textColor= [UIColor yellowColor]];

    isDateSearch=NO;
    self.arrTitles =[[NSMutableArray alloc] init];
    self.arrDescription=[[NSMutableArray alloc]init];
    self.arrImages=[[NSMutableArray alloc]init];
    self.arrDate=[[NSMutableArray alloc]init];
    self.arrUrls=[[NSMutableArray alloc]init];
    self.arrDateSearch=[[NSMutableArray alloc]init];
    //[self performSelectorInBackground:@selector(requestingForNews:) withObject:nil];

    // dispatch_async( dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), s^{
    self.spinnerView.hidden=YES;
    [self makeRequestForNews];
    //  self.spinnerView.stopAnimating;
    //});

    // Do any additional setup after loading the view.
    [self imagedownloader:@"http://www.shura.bh/MediaCenter/News/"];
}
-(void)requestingForNews:(id)sender
{
    [self makeRequestForNews];
}
-(void) imagedownloader : (NSString *)urlStringOfImage
{
    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
    dispatch_async(queue, ^{
        //downlaod image
        NSURL *imageUrl = [NSURL URLWithString:urlStringOfImage];
        NSData  *imageData = [NSData dataWithContentsOfURL:imageUrl];
        UIImage *image = [UIImage imageWithData:imageData];
        dispatch_async(dispatch_get_main_queue(), ^{

            UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 50, 50 )];
            imageView.image = image;
            [self.view addSubview:imageView];
        });
    });
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma  mark - make request for news
-(void)makeRequestForNews
{

    NSURL *url =[NSURL URLWithString:self.strNewsApi];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    //After making request the apparent thing is expecting the response that may be expected response or an Error. so create those objects and intialize them with NULL.
    NSURLResponse *response = NULL;
    NSError *requestError =NULL;
    //Once you have response with you , Capture YOur Responce data using NsData.

    NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&requestError];

    //Convert the respnse Data into Response String.

    NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];

    //Now We can start parsing the Data using XMl parser . you need XML parser in-order to use the below class method "dictionaryFOrXMLString".

    NSError *parserError = NULL;

    //XML parsing

    NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithData:responseData];
    [xmlParser setDelegate:self];
    [xmlParser parse];

    //    NSURL *url = [NSURL URLWithString:url];
    //    NSData *data = [NSData dataWithContentsOfURL:url];
    //    UIImage *image = [UIImage imageWithData:data];

    //NSDictionary *xmlDict = [XMLReader dictionaryForXMLString:responseString error:NULL];

    //once you have xmlDict handy, you can pass this to the any ViewController (Like table view) to populate the Data.
}

- (void)parserDidEndDocument:(NSXMLParser *)parser {

}
-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{


    if ([elementName isEqualToString:@"ShuraNews"])
    {

    }
    if ([elementName isEqualToString:@"PUBLISHINGPAGEIMAGE"])
    {

    }
    strTemp=[NSMutableString new];
}
-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
    //temString =string;
    [strTemp appendString:string];
}
-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
    if ([elementName isEqualToString:@"TITLE"])
    {
        NSLog(@"temstring=== %@", strTemp);
        [self.arrTitles addObject:strTemp];
    }
    if ([elementName isEqualToString:@"PUBLISHINGPAGECONTENT"])
    {
        NSLog(@"temstring=== %@", strTemp);
        [self.arrDescription addObject:strTemp];
    }
    if ([elementName isEqualToString:@"NEWSARTICLEDATE"])
    {
        NSLog(@"temstring=== %@", strTemp);
        [self.arrDate addObject:strTemp];
    }
    if ([elementName isEqualToString:@"PUBLISHINGPAGEIMAGE"])
    {

        NSLog(@"tempImage=== %@", strTemp);
        [self.arrImages addObject:strTemp];
    }
    if ([elementName isEqualToString:@"ShuraNews"])
    {
        [self.tblNews reloadData];
        // self.spinnerView.hidden=YES;
    }
    if ([elementName isEqualToString:@"URL"])
    {
        [self.arrUrls addObject:strTemp];
    }

}

#pragma mark - TabeView Datasource//delegate method

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (isDateSearch)
    {
        return [self.arrDateSearch count];
    }
    else{
        return [self.arrTitles count];
    }
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView setSeparatorInset:UIEdgeInsetsZero];
    static NSString *cellIdentifier=@"cellNews";
    NewsTableViewCell *cell=(NewsTableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];

    if (cell == nil)
    {
        cell = [[NewsTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
        // cell.NewsTableViewCell.textColor = UIColorFromRGB(0x000000);
        cell.backgroundColor=[UIColor clearColor];


    }

    if( [indexPath row] % 2){
        cell.contentView.backgroundColor =UIColorFromRGB(0Xffffff);

    }
    else{
        cell.contentView.backgroundColor =UIColorFromRGB (0Xdcdcdc);
    }

    //selectbackground color start
    UIView *NewsTableViewCell = [[UIView alloc] initWithFrame:cell.frame];
    NewsTableViewCell.backgroundColor = UIColorFromRGB(0Xdcdcdc);
    cell.selectedBackgroundView = NewsTableViewCell; //select background colro end
    cell.lblTitles.font = [UIFont fontWithName:@"GEEast-ExtraBold" size:12];
    if (isDateSearch)
    {
        cell.lblTitles.text=[[self.arrDateSearch objectAtIndex:indexPath.row]objectForKey:@"title"];
    }
    else{
        cell.lblTitles.text=[self.arrTitles objectAtIndex:indexPath.row];
    }
    cell.lblDescription.font =[UIFont fontWithName:@"GE SS Unique" size:12];
    cell.lblDate.font=[UIFont fontWithName:@"GE SS Unique" size:12];
    if (isDateSearch)
    {
        cell.lblDescription.text=[[self.arrDateSearch objectAtIndex:indexPath.row]objectForKey:@"des"];
    }
    else{
        cell.lblDescription.text=[self.arrDescription objectAtIndex:indexPath.row];
    }
    cell.lblDate.text=[self.arrDate objectAtIndex:indexPath.row];
    cell.lblTitles.textAlignment= NSTextAlignmentRight;
    cell.lblDate.textAlignment = NSTextAlignmentRight;
    cell.lblDescription.textAlignment = NSTextAlignmentRight;
    //SDWebImage Code for lazy loader
    [cell.imgNews setImageWithURL:[NSURL URLWithString:[self.arrImages objectAtIndex:indexPath.row]]

                        completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) {

                         //   if (![self.arrImages objectAtIndex:indexPath.row])
                            if ((cell.imgNews.image = image))
                            {
                                cell.imgNews.layer.borderColor = [UIColor blackColor].CGColor;
                                cell.imgNews.layer.borderWidth = 2.0;

                            }
                            else {

                             //  if (!cell.imgNews ==nil)
                            if (!cell.imgNews.image)
                                {

                                    cell.lblTitles.frame=CGRectMake(cell.lblTitles.frame.origin.x, cell.lblTitles.frame.origin.y, 283, cell.lblTitles.frame.size.height);
                                    cell.lblDate.frame=CGRectMake(cell.lblDate.frame.origin.x, cell.lblDate.frame.origin.y, 286, cell.lblDate.frame.size.height);
                                    cell.lblDescription.frame=CGRectMake(cell.lblDescription.frame.origin.x, cell.lblDescription.frame.origin.y, 281, cell.lblDescription.frame.size.height);
                                    cell.imgNews.layer.borderColor = [UIColor blackColor].CGColor;
                                    cell.imgNews.layer.borderWidth = 0;


                                }
                            }

                        }];

    // cell.imgNews.image=[UIImage imageWithData:data];
//    cell.imgNews.layer.borderColor = [UIColor blackColor].CGColor;
//    cell.imgNews.layer.borderWidth = 2.0;
    [PickerContainer setHidden:YES];
//    if (!cell.imgNews.image)
//    {
//        cell.lblTitles.frame=CGRectMake(cell.lblTitles.frame.origin.x, cell.lblTitles.frame.origin.y, 283, cell.lblTitles.frame.size.height);
//        cell.lblDate.frame=CGRectMake(cell.lblDate.frame.origin.x, cell.lblDate.frame.origin.y, 286, cell.lblDate.frame.size.height);
//        cell.lblDescription.frame=CGRectMake(cell.lblDescription.frame.origin.x, cell.lblDescription.frame.origin.y, 281, cell.lblDescription.frame.size.height);
//        cell.imgNews.layer.borderColor = [UIColor blackColor].CGColor;
//        cell.imgNews.layer.borderWidth = 0;
//    }
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSDictionary *dict=nil;
    if (isDateSearch)
    {
        //dict=[[NSDictionary alloc]initWithObjectsAndKeys:[NSString stringWithFormat:@"%@",[[self.arrDateSearch objectAtIndex:indexPath.row]objectForKey:@"title"]],@"title",[NSString stringWithFormat:@"%@",[[self.arrDateSearch objectAtIndex:indexPath.row]objectForKey:@"des"]],@"img",[NSString stringWithFormat:@"%@",[self.arrDescription objectAtIndex:indexPath.row]],@"Des",[NSString stringWithFormat:@"%@",[self.arrUrls objectAtIndex:indexPath.row]],@"url", nil];
    }
    else{
        dict=[[NSDictionary alloc]initWithObjectsAndKeys:[NSString stringWithFormat:@"%@",
                                                          [self.arrTitles objectAtIndex:indexPath.row]],@"title",[NSString stringWithFormat:@"%@",
                                                                                                                  [self.arrImages objectAtIndex:indexPath.row]],@"img",[NSString stringWithFormat:@"%@",
                                                                                                                                                                        [self.arrDescription objectAtIndex:indexPath.row]],@"Des",[NSString stringWithFormat:@"%@",[self.arrUrls objectAtIndex:indexPath.row]],@"url", nil];
    }
    [self performSegueWithIdentifier:@"NewsDetailsID" sender:dict];
}

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:@"NewsDetailsID"])
    {
        ((NewDetailsViewController *)segue.destinationViewController).strTitle=[sender objectForKey:@"title"];
        ((NewDetailsViewController *)segue.destinationViewController).strDetailImage=[sender objectForKey:@"img"];
        ((NewDetailsViewController *)segue.destinationViewController).strDescription=[sender objectForKey:@"Des"];//strUrl
        ((NewDetailsViewController *)segue.destinationViewController).strUrl=[sender objectForKey:@"url"];
    }
}

- (IBAction)backBtnClicked:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
}

- (IBAction)DatePickerBt:(id)sender {
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.3];
    PickerContainer.frame = CGRectMake(0, 150, 320, 261);
    [PickerContainer setHidden:NO];
}
- (IBAction)HideButton:(id)sender
{
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.3];
    PickerContainer.frame = CGRectMake(0,600, 320, 261);
    [UIView commitAnimations];

    if ([self.arrDateSearch count])
    {
        [self.arrDateSearch removeAllObjects];
    }
    if ([self.arrDate count])
    {
        for (int i=0; i<[self.arrDate count]; i++)
        {
            NSLog(@"arrdate === %@",self.arrDate);

            NSArray *arrDateStr=[[self.arrDate objectAtIndex:i] componentsSeparatedByString:@" "];
            NSArray *arrDat=[[NSString stringWithFormat:@"%@",[arrDateStr objectAtIndex:0]] componentsSeparatedByString:@"/"];

            NSString *strDat=[NSString stringWithFormat:@"%@-%@-%@",[arrDat objectAtIndex:2],[arrDat objectAtIndex:1],[arrDat objectAtIndex:0]];
            NSString *strPicDat=[[[NSString stringWithFormat:@"%@",self.datepicker.date]componentsSeparatedByString:@" "]objectAtIndex:0];
            NSLog(@" strpic date === %@",strPicDat);
            if ([strDat isEqualToString:strPicDat])
            {
                isDateSearch=YES;
                NSDictionary *dictTemp=[NSDictionary dictionaryWithObjectsAndKeys:[self.arrTitles objectAtIndex:i],@"title",[self.arrDescription objectAtIndex:i],@"des",[self.arrImages objectAtIndex:i],@"img", nil];
                [self.arrDateSearch addObject:dictTemp];
                NSLog(@"dates equal");
            }

        }

        [self.tblNews reloadData];

    }
}
- (IBAction)ReloadButton:(id)sender {
    self.spinnerView.hidden=NO;
    isDateSearch=NO;
    [self makeRequestForNews];
    NSLog(@"RELOADING!!!!!!!!!!!!!!!");

}
@end
#导入“NewsViewController.h”
#导入“NewsTableViewCell.h”
#导入“NewDetailsViewController.h”
#进口
#导入“SearchVC.h”
@接口NewsViewController()
{
NSString*temString;
NSMutableString*strTemp;
布尔数据搜索;
}
@结束
@NewsViewController的实现
@合成图像;
@合成滴定酮;
@合成滴定二;
@合成滴定三;
@综合数据采集器;
@合成PickerContainer;
@综合数据采集器;
-(id)initWithNibName:(NSString*)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil
{
self=[super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
如果(自我){
//自定义初始化
}
回归自我;
}
#pragma标记-视图生命周期
-(无效)viewDidLoad
{
UIActivityIndicatorView*spinnerView=[[UIActivityIndicatorView alloc]initWithActivityIndicator样式:UIActivityIndicatorView样式灰色];
[超级视图下载];
[TitleOne setFont:[UIFont fontWithName:@“GEEast ExtraBold”大小:12];
[标题二设置字体:[UIFont fontWithName:@“GEEast ExtraBold”大小:10];
[标题三设置字体:[UIFont fontWithName:@“GEEast ExtraBold”大小:10];
//[[UIColor redColor]集];
[DatePickerTitle setFont:[UIFont fontWithName:@“GEEast ExtraBold”大小:12];
//[DatePickerTitle.textColor=[UIColor yellowColor]];
isDateSearch=否;
self.arrTitles=[[NSMutableArray alloc]init];
self.arrDescription=[[NSMutableArray alloc]init];
self.arrImages=[[NSMutableArray alloc]init];
self.arrDate=[[NSMutableArray alloc]init];
self.arruls=[[NSMutableArray alloc]init];
self.arrDateSearch=[[NSMutableArray alloc]init];
//[self-performSelectorInBackground:@selector(requestingForNews:)with object:nil];
//调度异步(调度获取全局队列(调度队列优先级默认为0),s^{
self.spinnerView.hidden=是;
[自拍新闻];
//self.spinnerView.stop设置动画;
//});
//加载视图后执行任何其他设置。
[自映像下载程序:@”http://www.shura.bh/MediaCenter/News/"];
}
-(无效)requestingForNews:(id)发件人
{
[自拍新闻];
}
-(void)imagedownloader:(NSString*)urlStringOfImage
{
调度队列=调度获取全局队列(调度队列优先级高,0ul);
调度异步(队列^{
//下行图像
NSURL*imageUrl=[NSURL URLWithString:urlStringOfImage];
NSData*imageData=[NSData dataWithContentsOfURL:imageUrl];
UIImage*image=[UIImage imageWithData:imageData];
dispatch\u async(dispatch\u get\u main\u queue()^{
UIImageView*imageView=[[UIImageView alloc]initWithFrame:CGRectMake(0,0,50,50)];
imageView.image=图像;
[self.view addSubview:imageView];
});
});
}
-(无效)未收到记忆警告
{
[超级记忆警告];
//处置所有可以重新创建的资源。
}
#布拉格语标记-请求新闻
-(void)makeRequestForNews
{
NSURL*url=[NSURL-URLWithString:self.strNewsApi];
NSURLRequest*request=[nsurlRequestRequestWithURL:url];
//发出请求后,明显的情况是期望响应可能是期望响应或错误。因此,创建这些对象并使用NULL初始化它们。
NSURLResponse*response=NULL;
NSError*requestError=NULL;
//一旦有了响应,就可以使用NsData捕获响应数据。
NSData*responseData=[NSURLConnection sendSynchronousRequest:request ReturnInResponse:&response error:&requestError];
//将响应数据转换为响应字符串。
NSString*responseString=[[NSString alloc]initWithData:responseData编码:NSUTF8StringEncoding];
//现在我们可以开始使用XMl解析器解析数据了。
NSError*parserError=NULL;
//XML解析
NSXMLParser*xmlParser=[[NSXMLParser alloc]initWithData:responseData];
[xmlParser setDelegate:self];
[xmlParser parse];
//NSURL*url=[NSURL URLWithString:url];
//NSData*data=[NSData dataWithContentsOfURL:url];
//UIImage*image=[UIImage imageWithData:data];
//NSDictionary*xmlDict=[XMLReader dictionaryForXMLString:responseString错误:NULL];
//一旦您手边有了xmlDict,就可以将其传递给任意ViewController(如表视图)来填充数据。
}
-(void)parserDidEndDocument:(NSXMLParser*)解析器{
}
-(void)parser:(NSXMLParser*)parser didStartElement:(NSString*)elementName namespaceURI:(NSString*)namespaceURI qualifiedName:(NSString*)qName属性:(NSDictionary*)attributeDict
{
if([elementName IsequalString:@“ShuraNews”])
{
}
if([elementName IsequalString:@“PUBLISHINGPAGEIMAGE”])
{
}
strTemp=[NSMutableString new];
}
-(void)解析器:(NSXMLParser*)解析器查找字符:(NSString*)字符串
{
//temString=字符串;
[strTemp appendString:string];
}
-(void)parser:(NSXMLParser*)parser didEndElement:(NSString*)elementName namespaceURI:(NSString*)namespaceURI qualifiedName:(NSString*)qName
{
if([elementName IsequalString:@“TITLE”])
{
NSLog(@“temstring==%@”,strTemp);
[self.addObject:strTemp];
}
if([elementName IsequalString:@“PUBLISHINGPAGECONTENT”])
{
NSLog(@“temstri
-(void) imagedownloader : (NSString *)urlStringOfImage
{
    urlStringOfImage = [urlStringOfImage stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];

//OR

    urlStringOfImage = [urlStringOfImage stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

 // DO YOUR NORMAL STUFF YOU WERE DOING.

}
urlStringOfImage = [urlStringOfImage stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];