メディア事業部EC事業部 AGENCY事業部
メディア事業部ブログ
前のページへは、ブラウザの戻るボタンでお戻りください。
arefin

iPhone, Get XML from Server and Parse that XML and make a tableView

:!: :!: :!:
- (void)viewWillAppear:(BOOL)animated{

// Update the view with current data before it is displayed.
[super viewWillAppear:animated];

feedList = [[NSMutableArray alloc] initWithCapacity:0];

/*
NSString *sendUrl = @”http://coumori.test-gbleu.com/f_appli/i_area.php”;
NSURL *areaURL = [NSURL URLWithString:sendUrl];
NSError *error;
NSString *areaXml = [NSString stringWithContentsOfURL:areaURL encoding:NSUTF8StringEncoding error:&error];

NSData *areaXmlData = [areaXml dataUsingEncoding:NSUTF8StringEncoding];
*/

NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *fileName = [NSHomeDirectory() stringByAppendingPathComponent:@"tmp/area.xml"];
NSData *xmldData = [fileManager contentsAtPath:fileName];

NSXMLParser *nextParser = [[NSXMLParser alloc] initWithData:xmldData];

[nextParser setDelegate:self];
[nextParser parse];

// Scroll the table view to the top before it appears
[self.tableView reloadData];

}

:!: :!: :!:

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

if ([elementName compare:@"item"] == NSOrderedSame) {
currentItem = [[NSMutableDictionary alloc] initWithCapacity:0];
} else if (currentItem != NULL) {
currentContents = [[NSMutableString alloc] initWithCapacity:0];
}

}

:!: :!: :!:
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {

if (currentContents && string) {

[currentContents appendString:string];
}
}

:!: :!: :!:
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {

if ([elementName compare:@"item"] == NSOrderedSame) {

[feedList addObject:currentItem];
[currentItem release];
} else if (currentItem && currentContents) {
[currentItem setObject:currentContents forKey:elementName];
currentContents = nil;
[currentContents release];

}

}

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

[parser release];

}

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

:!: :!: :!:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [feedList count];
}

:!: :!: :!:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @”BigCategory”;

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];

//cell.selectionStyle = UITableViewCellSelectionStyleBlue;
}

if ([[feedList objectAtIndex:indexPath.row] objectForKey:@”title”]) {
cell.textLabel.text = [[feedList objectAtIndex:indexPath.row] objectForKey:@”title”];
}

//if ([[feedList objectAtIndex:indexPath.row] objectForKey:@”id”]) {
// cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
//}

return cell;

}

カテゴリー:iPad, iPhone , 投稿者名:Arefin Khandoker
PAGE TOP
ページトップへ