svp comment implementer dataWithContentsOfURL pour DetailControleView avec prepareforsegue
trysity 1307
Membre
voici mon bout de code viewcontroller.m
#import "ViewController.h"
#import "DetailViewController.h"
@interface ViewController ()
{
NSMutableArray *myObject;
// A dictionary object
NSMutableDictionary *dict;
// Define keys
NSString *id_vol;
NSString *SV;
NSString *Depart;
NSString *id_aerop;
NSString *date;
NSString *Heure;
NSString *commentaire;
NSString *id_companie;
// Current Element
NSString *currentElement;
// Temp Variable
NSMutableString *currentId_vol, *currentSV, *currentDepart, *currentid_aerop,*currentDate,*currentHeure,*currentCommentaire,*currentId_companie;
NSXMLParser *xmlParser;
}
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
// Define keys
id_vol = @id_vol;
SV = @SV;
Depart = @Depart;
id_aerop = @id_aerop;
date = @date;
Heure = @Heure;
commentaire = @commentaire;
id_companie = @id_companie;
// Create array to hold dictionaries
myObject = [[NSMutableArray alloc] init];
NSURL *xmlURL = [NSURL URLWithString:@"http://localhost:8888/avion.php"];
xmlParser = [[NSXMLParser alloc] initWithContentsOfURL:xmlURL];
[xmlParser setDelegate: self];
[xmlParser parse];
}
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{
currentElement = [elementName copy];
if([elementName isEqualToString: @vol]){
dict = [[NSMutableDictionary alloc] init];
currentId_vol = [[NSMutableString alloc] init];
currentSV= [[NSMutableString alloc] init];
currentDepart = [[NSMutableString alloc] init];
currentid_aerop = [[NSMutableString alloc] init];
currentDate = [[NSMutableString alloc] init];
currentHeure = [[NSMutableString alloc] init];
currentCommentaire = [[NSMutableString alloc] init];
currentId_companie = [[NSMutableString alloc] init];
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{
/*
if([currentElement isEqualToString: @GalleryID]){
[currentGalleryID appendString: string];
}else if([currentElement isEqualToString: @Name]){
[currentName appendString: string];
}else if([currentElement isEqualToString: @TitleName]){
[currentTitleName appendString: string];
}else if([currentElement isEqualToString: @Thumbnail]){
[currentThumbnail appendString: string];
}
*/
if(!string stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet isEqualToString: @""]){
if([currentElement isEqualToString: id_vol]){
[currentId_vol appendString: string];
}else if([currentElement isEqualToString: SV]){
[currentSV appendString: string];
}else if([currentElement isEqualToString: Depart]){
[currentDepart appendString: string];
}else if([currentElement isEqualToString: id_aerop]){
[currentid_aerop appendString: string];
}else if([currentElement isEqualToString: date]){
[currentDate appendString: string];
}else if([currentElement isEqualToString: Heure]){
[currentHeure appendString: string];
}else if([currentElement isEqualToString: commentaire]){
[currentCommentaire appendString: string];
}else if([currentElement isEqualToString: id_companie]){
[currentId_companie appendString: string];
}
}
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{
/*
if([elementName isEqualToString: @""GalleryID]){
[dict setObject: currentGalleryID forKey: @GalleryID];
}else if([elementName isEqualToString: @Name]){
[dict setObject: currentName forKey: @Name];
}else if([elementName isEqualToString: @TitleName]){
[dict setObject: currentTitleName forKey : @TitleName];
}else if([elementName isEqualToString: @Thumbnail]){
[dict setObject: currentThumbnail forKey: @Thumbnail];
}else if([elementName isEqualToString: @image]){
[myObject addObject: dict];
}
*/
if([elementName isEqualToString: id_vol]){
[dict setObject: currentId_vol forKey:id_vol];
}else if([elementName isEqualToString: SV]){
[dict setObject: currentSV forKey: SV];
}else if([elementName isEqualToString: Depart]){
[dict setObject: currentDepart forKey: Depart];
}else if([elementName isEqualToString: id_aerop]){
[dict setObject: currentid_aerop forKey: id_aerop];
}else if([elementName isEqualToString: date]){
[dict setObject: currentDate forKey: date];
}else if([elementName isEqualToString: Heure]){
[dict setObject: currentHeure forKey: Heure];
}else if([elementName isEqualToString: commentaire]){
[dict setObject: currentCommentaire forKey: commentaire];
}else if([elementName isEqualToString: id_companie]){
[dict setObject: currentId_companie forKey: id_companie];
// Add Object
}else if([elementName isEqualToString: @vol]){
[myObject addObject: dict];
}
}
- (void)parserDidEndDocument:(NSXMLParser *)parser {
NSLog(@flight list array has %d items, [myObject count]);
NSMutableDictionary *flight;
for(int i = 0; i < [myObject count]; i ++){
flight = [myObject objectAtIndex: i];
NSLog(@\nid_vol: %@\nSV: %@\nDepart: %@\nid_aerop: %@\ndate: %@\nHeure: %@\ncommentaire:%@\nid_companie: %@\n\n",
[flight objectForKey: id_vol],
[flight objectForKey: SV],
[flight objectForKey: Depart],
[flight objectForKey: id_aerop],
[flight objectForKey: date],
[flight objectForKey: Heure],
[flight objectForKey: commentaire],
[flight objectForKey: id_companie]);
}
// Reload Data
[_myTable reloadData];
}
// delegate for TableView
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return myObject.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @Cell;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
// Use the default cell style.
cell = [[[UITableViewCell alloc] initWithStyle : UITableViewCellStyleSubtitle
reuseIdentifier : CellIdentifier] autorelease];
}
NSDictionary *tmpDict = [myObject objectAtIndex:indexPath.row];
NSURL *url = [NSURL URLWithString:[tmpDict objectForKey:id_companie]];
NSData *data = [NSData dataWithContentsOfURL:url];
//UIImage *img = [[UIImage alloc] initWithData:data];
//cell.imageView.image = img;
cell.textLabel.textColor = [UIColor colorWithRed:0 green:0.4 blue:0.8 alpha:1];
cell.detailTextLabel.textColor=[UIColor colorWithRed:0.5 green:0.1 blue:0.0 alpha:1];
cell.textLabel.text = [tmpDict objectForKey:id_companie];
cell.detailTextLabel.text= [tmpDict objectForKey:Heure];
cell.detailTextLabel.numberOfLines=3;
//[tmpDict objectForKey:id_companie];
//[tmpDict objectForKey:id_aerop];
//[tmpDict objectForKey:id_vol];
//[tmpDict objectForKey:date];
return cell;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)dealloc {
[_myTable release];
[super dealloc];
}
Connectez-vous ou Inscrivez-vous pour répondre.
Réponses
Alors...
Je ne vais pas répéter ce qu'a dit AliGator, mais je n'en pense pas moins.
Le titre est ambigà¼e. Je n'ai pas réellement compris ton problème.
J'ai regardé vite fait le code (mais sans balise code, c'est pas top).
Le soucis est à quel endroit ?
Je n'ai pas vu tableView:didSelectRowAtIndexPath
Tu parles de prepareForSegue, mais je ne le vois nulle part.