- (void)viewDidLoad
{
NSURL *url=[[NSURL alloc]initWithString:@"http://avweatherforecasts.com/services/iphoneservice.php"];
DaTa=[[NSData alloc]initWithContentsOfURL:url];
NSLog(@"data----%@",DaTa);
Xmlpaeser=[[NSXMLParser alloc]initWithData:DaTa];
Xmlpaeser.delegate=self;
[Xmlpaeser parse];
[Xmlpaeser release];
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)parserDidStartDocument:(NSXMLParser *)parser{
array=[[NSMutableArray alloc]init];
strcontent=nil;
}
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{
if ([elementName isEqualToString:@"start"])
{
Dict=[[NSMutableDictionary alloc]init];
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{
strcontent=[NSString stringWithFormat:@"%@",string];
NSLog(@"Strcontent----%@",strcontent);
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{
if ([elementName isEqualToString:@"city"]){
[Dict setObject:strcontent forKey:elementName];
}
if ([elementName isEqualToString:@"min"]){
[Dict setObject:strcontent forKey:elementName];
}
if ([elementName isEqualToString:@"max"]){
[Dict setObject:strcontent forKey:elementName];
}
if ( [elementName isEqualToString:@"forecast"]
) {
[Dict setObject:strcontent forKey:elementName];
NSLog(@"dict--%@",[Dict description]);
}
else if([elementName isEqualToString:@"start"]){
[array addObject:Dict];
[Dict release];
}
}
- (void)parserDidEndDocument:(NSXMLParser *)parser{
NSLog(@"array--%@",[array description]);
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [array count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *identifier=@"cell";
custome_cell *Cell=(custome_cell *)[tableView dequeueReusableCellWithIdentifier:identifier];
if (Cell==nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"custome_cell" owner:self options:nil];
Cell = [nib objectAtIndex:indexPath.row];
}
Cell.city.text=[[array objectAtIndex:indexPath.row] objectForKey:@"city"];
Cell.min.text=[[array objectAtIndex:indexPath.row] objectForKey:@"min"];
Cell.max.text=[[array objectAtIndex:indexPath.row] objectForKey:@"max"];
Cell.forecast.text =[[array objectAtIndex:indexPath.row] objectForKey:@"forecast"];
return Cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 80;
}