The issue I’m running into is I have an NSMutableArray labeled: _podAllEntries, which contains url paths. The contents of this array are then loaded into one row in my UITableView. There are a total of 4 items in this array and there should be an entry in the table per item. Below is a more detailed explination of how the app works:
This iOS app uses NSURL to consume XML data from a website: http://undignified.podbean.com/feed. From there I parse through the XML using NSXMLParser and search for an attribute called “url” within the “enclosure” element. All attributes that match “url” are then added to an array and then should be loaded in the UITableView with each item on a separate row (as previously mentioned, there is only one row filled).
I’m probably missing something minor at this point and a nudge in the right direction or any feedback would be greatly appreciated.
UnDigParser.h
Header file for parsing class:
#import <Foundation/Foundation.h>
@interface UnDigParser : NSXMLParser <NSXMLParserDelegate> {
}
@property (retain) NSMutableArray *links;
@end
UnDigParser.m
Implementation for for parsing class:
#import "UnDigParser.h"
@implementation UnDigParser
NSMutableArray *_links;
@synthesize links = _links;
-(void)parserDidStartDocument:(NSXMLParser *)parser{
_links=[[NSMutableArray alloc] init];
}
-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
if ([elementName isEqualToString:@"enclosure"]){
NSString *link = [attributeDict objectForKey:@"url"];
if (link){
[_links addObject:link];
}
}
//NSLog(@"%@",_links);
}
-(BOOL)parse{
self.delegate = self;
return [super parse];
}
@end
ViewController.h
@class WebViewController;
@interface getpodViewController : UITableViewController <UITableViewDataSource>
{
NSMutableArray *_podAllEntries;
NSMutableArray *_allEntries;
WebViewController *_webViewController;
}
@property(retain) NSMutableArray *podAllEntries;
@property(retain) NSMutableArray *allEntries;
@property(retain) WebViewController *webViewController;
@end
ViewController.m
@implementation getpodViewController
@synthesize podAllEntries = _podAllEntries;
@synthesize allEntries = _allEntries;
@synthesize webViewController = _webViewController;
-(void)addRows
{
//dispatch_async(dispatch_get_global_queue(0, 0), ^{
NSURL *url = [NSURL URLWithString:@"http://undignified.podbean.com/feed"];
UnDigParser *parser = [[UnDigParser alloc] initWithContentsOfURL:url];
[parser parse];
[_podAllEntries insertObject:parser.links atIndex:0];
NSLog(@"%@", _podAllEntries);
[self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:0 inSection:0]]
withRowAnimation:UITableViewRowAnimationRight];
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = @"Podcasts";
self.podAllEntries = [[NSMutableArray alloc]init];
[self addRows];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [_podAllEntries count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell==nil){
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}
NSString *cellValue = [NSString stringWithFormat:@"%@", _podAllEntries];
cell.textLabel.text = cellValue;
return cell;
}
You need to do it like this:
Example:
You can also remove the following statement from
addRowssincecellForRowAtIndexPath:is where the cells will actually be created.