我升级了代码,然后下面的代码标题有22个对象,16个对象为空,之类的另一个对象是nil。为什么它发生,我写代码就像elementame是eqale到项目然后它正常工作。但是当将数据从一个视图控制器传递到另一个视图控制器有问题。 请给出解决方案,然后发送每个项目的链接,然后使用模型编写图像和描述的代码。
所以请帮助我。
NSURL *url = [NSURL URLWithString:@"http://www.cinejosh.com/rss-feed/4/telugu.html"];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:30];
NSURLConnection *urlConnection = [NSURLConnection connectionWithRequest:urlRequest delegate:self];
if(urlConnection){
self.responseData = [NSMutableData data];
}
else
{
NSLog(@"the connection failed");
}
}
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
[self.responseData setLength:0];
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[self.responseData appendData:data];
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
self.cnnParser = [[NSXMLParser alloc]initWithData:self.responseData];
self.cnnParser.delegate = self;
[self.cnnParser parse];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
[self.homeActivityIndicator stopAnimating];
[self.activityView setHidden:YES];
UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"Connection Failed" message:nil delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
alertView.delegate = self;
[alertView show];
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
[self.navigationController popToRootViewControllerAnimated:YES];
}
-(void)parserDidStartDocument:(NSXMLParser *)parser
{
titlesTag = NO;
datesTag = NO;
descriptionsTag = NO;
linksTag = NO;
itemsTag = NO;
}
-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
if([elementName isEqualToString:@"item"])
{
itemsTag = YES;
}
else if([elementName isEqualToString:@"title"])
{
titlesTag = YES;
}
else if([elementName isEqualToString:@"link"])
{
linksTag = YES;
}
else if([elementName isEqualToString:@"description"])
{
descriptionsTag = YES;
}
else if([elementName isEqualToString:@"pubDate"])
{
datesTag = YES;
}
}
-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
if(titlesTag == YES && itemsTag == YES)
{
[titlesArray addObject:string];
NSLog(@"title %lu",[titlesArray count]);
}
else if(linksTag == YES && itemsTag == YES)
{
[self.linksArray addObject:string];
}
else if(descriptionsTag == YES && itemsTag == YES)
{
[self.descriptionsArray addObject:string];
}
else if(datesTag == YES && itemsTag == YES)
{
[self.datesArray addObject:string];
NSLog(@"date %lu",(unsigned long)[datesArray count]);
}
}
-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if([elementName isEqualToString:@"title"])
{
titlesTag = NO;
// itemsTag = NO;
}
else if([elementName isEqualToString:@"link"])
{
linksTag = NO;
}
else if([elementName isEqualToString:@"description"])
{
descriptionsTag = NO;
}
else if([elementName isEqualToString:@"pubDate"])
{
datesTag = NO;
// itemsTag = NO;
}
else if ([elementName isEqual:@"item"])
{
itemsTag=NO;
}
}