iphone- UITableView displaying only one value - iphone

My UITableView is not displaying all values after parsing XML. It returns only one row. After parsing xml, why is only one row being shown and not the whole ArrayList? I have checked my xml php page. It is showing all values fine.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [[xmlcont xmlbanktransfer] count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSUInteger const kMagnitudeImageTag = 0;
static NSUInteger const kLocationLabelTag = 4;
static NSUInteger const klocationtag = 6;
static NSUInteger const kacctag = 8;
static NSUInteger const knameLabelTag = 9;
UIImageView *magnitudeImage = nil;
UILabel*locationLabel = nil;
UILabel*locationtag=nil;
UILabel*acc=nil;
UILabel*nameLabel= nil;
//NSMutableArray *cont = [xmlcont tweets];
// Tweet *current       = [cont objectAtIndex:indexPath.row];
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
/*//common settings
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
cell.imageView.contentMode = UIViewContentModeScaleAspectFill;
cell.imageView.frame = CGRectMake(0.0f, 0.0f, 44.0f, 44.0f);
cell.imageView.clipsToBounds = YES;
*/
}
for(UIView *view in cell.contentView.subviews)
{
if ([view isKindOfClass:[UIView class]])
{
[view removeFromSuperview];
}
}
NSMutableArray *cont = [xmlcont xmlbanktransfer];
trans *current= [cont objectAtIndex:indexPath.row];
NSLog(#"sd %#",current.date);
NSLog(#"sd %#",current.name);
locationLabel = [[UILabel alloc] initWithFrame:CGRectMake(5,10, 250, 20)];
locationLabel.tag = kLocationLabelTag;
locationLabel.font = [UIFont boldSystemFontOfSize:15];
[cell.contentView addSubview:locationLabel];
locationLabel.text=current.name;
locationLabel.textColor=[UIColor colorWithRed:0.050 green:0.278 blue:0.392 alpha:1];
//locationLabel.backgroundColor=[UIColor lightGrayColor];
locationLabel.backgroundColor=[UIColor colorWithRed:225 green:225 blue:225 alpha:0] ;
nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(180,10, 250, 20)];
nameLabel.tag = knameLabelTag;
nameLabel.font = [UIFont systemFontOfSize:13];
[cell.contentView addSubview:nameLabel];
nameLabel.text=current.date ;
nameLabel.textColor=[UIColor colorWithRed:0.050 green:0.278 blue:0.392 alpha:1];
//locationLabel.backgroundColor=[UIColor lightGrayColor];
nameLabel.backgroundColor=[UIColor colorWithRed:225 green:225 blue:225 alpha:0] ;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
code for parsing xml:
xmlbanktransfer=[[NSMutableArray alloc] init];
NSURL *url=[NSURL URLWithString:[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
parser=[[NSXMLParser alloc] initWithContentsOfURL:url];
[parser setDelegate:self];
[parser parse];
NSLog(#"testing12 %# ",url);
// NSLog(#"tweets %# ", xmlbanktransfer);
NSLog(#"Total values = %d",[xmlbanktransfer count]);
return self;
}
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
if([elementName isEqualToString:#"item"])
{
currentTweet = [trans alloc];
banktransNodeContent =[[NSMutableString alloc] init];
}
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if([elementName isEqualToString:#"date"])
{
currentTweet.date = [currentTweet.date stringByReplacingOccurrencesOfString:#"&" withString:#" "];
currentTweet.date = banktransNodeContent;
}
if([elementName isEqualToString:#"name"])
{
currentTweet.name =banktransNodeContent;
}
if ([elementName isEqualToString:#"type"])
{
currentTweet.type=banktransNodeContent;
}
if ([elementName isEqualToString:#"gross"])
{
currentTweet.gross=banktransNodeContent;
}
if ([elementName isEqualToString:#"fee"])
{
currentTweet.fee=banktransNodeContent;
}
if ([elementName isEqualToString:#"net"])
{
currentTweet.net=banktransNodeContent;
NSLog(#"current tweet %#",currentTweet.net);
}
if ([elementName isEqualToString:#"category"])
{
currentTweet.category=banktransNodeContent;
NSLog(#"current tweet %#",currentTweet.category);
}
if ([elementName isEqualToString:#"account"])
{
currentTweet.account=banktransNodeContent;
NSLog(#"current tweet %#",currentTweet.account);
}
if([elementName isEqualToString:#"item"])
{
[xmlbanktransfer addObject:currentTweet];
currentTweet = nil;
banktransNodeContent = nil;
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
NSLog(#"currentNodeContent are %#",banktransNodeContent);
banktransNodeContent = [string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSLog(#"currentNodeContentstring test are %#",banktransNodeContent);
}
- (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock
{
banktransNodeContent = [[NSString alloc] initWithData:CDATABlock encoding:NSUTF8StringEncoding];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [[xmlcont xmlbanktransfer] count];
}
this method tells the tableview how many cells to populate
Log the value and see how much it is returning [it must be 1 returning now,since the table shows one row].Correct the return value and you have all values displayed
Things to check
Returning value mentioned above
Make sure the array xmlbanktransfer is a property which is of strong type

Related

i'm trying to display xml data in custom cell but it's working, and it display only one data [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
- (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;
}
Try this...May be it will help you...
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [CommentsGetArray 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] ;
//[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
commentsTextView = [[UITextView alloc]initWithFrame:CGRectMake(90, 4, 190, 50)];
commentsTextView.delegate = self;
commentsTextView.tag = 101;
commentsTextView.textAlignment = UITextAlignmentLeft;
[commentsTextView setScrollEnabled:YES];
commentsTextView.backgroundColor =[UIColor clearColor];
commentsTextView.font = [UIFont fontWithName:#"Arial" size:12.0];
commentsTextView.textColor =[UIColor blackColor];
commentsTextView.editable = NO;
[cell addSubview:commentsTextView];
}
commentsTextView = (UITextView *)[cell viewWithTag:101];
commentsTextView.text = [[CommentsGetArray objectAtIndex:indexPath.row]objectForKey:#"comment"];
return cell;
}
- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 70;
}
you can use as a label instead of uitextView and you can create more text views or label to show your data but remember change their frames.

not getting entire xml data into tableview

im parsing xml data into table view,here iam retrieving question and answer tags,problem occured in question tag only one question was displayed remaining questions not displayed ,this is the web service http://www.cmellc.com/DesktopModules/CaseChallenge/quiz.xml
this is the code i wrote
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
currentTag = elementName;
if ([currentTag isEqualToString:#"question"])
{
model = [[ModelDataView alloc]init];
}
if([currentTag isEqualToString:#"answer"])
{
model_2=[[Model2 alloc]init];
}
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if([elementName isEqualToString:#"question"])
{
[dataControllerArray addObject:model];
}
if ([elementName isEqualToString:#"answer"])
{
[dataControllerArray2 addObject:model_2];
model_2 = nil;
}
currentTag = nil;
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
if ([currentTag isEqualToString:#"result"])
{
model_2.result = string;
}
if ([currentTag isEqualToString:#"notes"])
{
model_2.notes = string;
}
if ([currentTag isEqualToString:#"question"])
{
model.question = string;
}
}
this is code for tableview methods
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = #"cell";
static NSString *cellIdentifier2 = #"cell2";
UITableViewCell *cell;
if(tableView.tag==2)
{
cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier] autorelease];
}
Model2 *obj=[modelController.dataControllerArray2 objectAtIndex:indexPath.row];
NSString *res=obj.result;
cell.textLabel.text=res;
return cell;
}
else if(tableView.tag==1)
{
cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier2];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier2] autorelease];
}
ModelDataView *obj=[modelController.dataControllerArray objectAtIndex:indexPath.row];
NSString *res=obj.question;
UIWebView *_webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 190)];
[self.view addSubview:_webView];
CGRect frame = _webView.frame;
frame.size.height = 190;
_webView.frame = frame;
[_webView loadHTMLString:res baseURL:[NSURL URLWithString:res]];
return cell;
}
}
thank you for helping me

Parsing XML in my iPhone application

I parsing some elements from a xml file located on my server to my app.This is the code to parse all elements:
-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict {
if ( [elementName isEqualToString:#"ipayregs"] ) {
msgAdded = [[attributeDict objectForKey:#"added"] retain];
msgId = [[attributeDict objectForKey:#"id"] intValue];
msgNome = [[NSMutableString alloc] init];
msgName = [[NSMutableString alloc] init];
msgMatricula = [[NSMutableString alloc] init];
msgSenderCode = [[NSMutableString alloc] init];
inNome = NO;
inName = NO;
inMatricula = NO;
inSenderCode = NO;
}
if ( [elementName isEqualToString:#"nome"] ) { inNome = YES; }
if ( [elementName isEqualToString:#"nome"] ) { inName = YES; }
if ( [elementName isEqualToString:#"matricula"] ) { inMatricula = YES; }
if ( [elementName isEqualToString:#"sendercode"] ) { inSenderCode = YES; }
}
-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
if ( inNome ) { [msgNome appendString:string]; }
if ( inName ) { [msgName appendString:string]; }
if ( inMatricula ) { [msgMatricula appendString:string]; }
if ( inSenderCode ) { [msgSenderCode appendString:string]; }
}
-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
if ( [elementName isEqualToString:#"ipayregs"] ) {
[messages addObject:[NSDictionary dictionaryWithObjectsAndKeys:msgAdded,#"added",msgNome,#"nome",msgMatricula,#"matricula",msgSenderCode,#"sendercode",msgName,#"name",nil]];
[[messages reverseObjectEnumerator] allObjects];
lastId = msgId;
[msgAdded release];
[msgNome release];
[msgName release];
[msgMatricula release];
[msgSenderCode release];
}
if ( [elementName isEqualToString:#"nome"] ) { inNome = NO;}
if ( [elementName isEqualToString:#"name"] ) { inName = NO;}
if ( [elementName isEqualToString:#"matricula"] ) { inMatricula = NO;}
if ( [elementName isEqualToString:#"sendercode"] ) { inSenderCode = NO;}
}
As you can see all data is placed in a array to be displayed after on a UITableView,using this code:
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
-(NSInteger)tableView:(UITableView *)myTableView numberOfRowsInSection:(NSInteger)section {
return ( messages == nil ) ? 0 : [messages count];
}
-(UITableViewCell *)tableView:(UITableView *)myTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = (UITableViewCell *)[self.messageList dequeueReusableCellWithIdentifier:#"newsCustomCell"];
if (cell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"newsCustomCell" owner:self options:nil];
cell = (UITableViewCell *)[nib objectAtIndex:0];
}
NSDictionary *itemAtIndex = (NSDictionary *)[messages objectAtIndex:indexPath.row];
UILabel *timeDate = (UILabel *)[cell viewWithTag:1];
timeDate.text = [itemAtIndex objectForKey:#"added"];
UILabel *userL = (UILabel *)[cell viewWithTag:2];
userL.text = [itemAtIndex objectForKey:#"nome"];
UILabel *textL2 = (UILabel *)[cell viewWithTag:3];
textL2.text = [itemAtIndex objectForKey:#"matricula"];
UILabel *textL3 = (UILabel *)[cell viewWithTag:4];
textL3.text = [itemAtIndex objectForKey:#"sendercode"];
return cell;
}
Ok,now is my problem,how can i make a UILabel display the value of the strings,per example the #"nome",be displayed in a UILabel when the view loads.It's related to this piece of code:
NSDictionary *itemAtIndex = (NSDictionary *)[messages objectAtIndex:indexPath.row];
But i don't know how i can set it up.

Need help with memory leaks in RSS Reader

I'm trying to write a simple RSS reader for the iPhone, and it appeared to be working fine, until I started working with Instruments, and discovered my App is leaking massive amounts of memory.
I'm using the NSXMLParser class to parse an RSS feed. My memory leaks appear to be originating from the overridden delegate methods:
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
and
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
I'm also suspicious of the code that populates the cells from my parsed data, I've included the code from those methods and a few other key ones, any insights would be greatly appreciated.
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
if ([self.currentElement isEqualToString:#"title"]) {
[self.currentTitle appendString:string];
} else if ([self.currentElement isEqualToString:#"link"]) {
[self.currentURL appendString:string];
} else if ([self.currentElement isEqualToString:#"description"]) {
[self.currentSummary appendString:string];
}
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
if ([elementName isEqualToString:#"item"]) {
//asdf
NSMutableDictionary *item = [[NSMutableDictionary alloc] init];
[item setObject:currentTitle forKey:#"title"];
[item setObject:currentURL forKey:#"URL"];
[item setObject:currentSummary forKey:#"summary"];
[self.currentTitle release];
[self.currentURL release];
[self.currentSummary release];
[self.stories addObject:item];
[item release];
}
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell.
// Set up the cell
int index = [indexPath indexAtPosition: [indexPath length] - 1];
CGRect contentRect = CGRectMake(8.0, 4.0, 260, 20);
UILabel *textLabel = [[UILabel alloc] initWithFrame:contentRect];
if (self.currentLevel == 0) {
textLabel.text = [self.categories objectAtIndex: index];
} else {
textLabel.text = [[self.stories objectAtIndex: index] objectForKey:#"title"];
}
textLabel.textColor = [UIColor blackColor];
textLabel.font = [UIFont boldSystemFontOfSize:14];
[[cell contentView] addSubview: textLabel];
//[cell setText:[[stories objectAtIndex: storyIndex] objectForKey: #"title"]];
[textLabel autorelease];
return cell;
}
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict {
if ([elementName isEqualToString:#"item"]) {
self.currentTitle = [[NSMutableString alloc] init];
self.currentURL = [[NSMutableString alloc] init];
self.currentSummary = [[NSMutableString alloc] init];
}
if (currentElement != nil) {
[self.currentElement release];
}
self.currentElement = [elementName copy];
}
- (void)dealloc {
[currentElement release];
[currentTitle release];
[currentURL release];
[currentSummary release];
[currentDate release];
[stories release];
[rssParser release];
[storyTable release];
[super dealloc];
}
// Override to support row selection in the table view.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Navigation logic may go here -- for example, create and push another view controller.
// AnotherViewController *anotherViewController = [[AnotherViewController alloc] initWithNibName:#"AnotherView" bundle:nil];
int index = [indexPath indexAtPosition: [indexPath length] - 1];
if (currentLevel == 1) {
StoryViewController *storyViewController = [[StoryViewController alloc] initWithURL:[[stories objectAtIndex: index] objectForKey:#"URL"] nibName:#"StoryViewController" bundle:nil];
[self.navigationController pushViewController:storyViewController animated:YES];
[storyViewController release];
} else {
RootViewController *rvController = [[RootViewController alloc] initWithNibName:#"RootViewController" bundle:nil];
rvController.currentLevel = currentLevel + 1;
rvController.rssIndex = index;
[self.navigationController pushViewController:rvController animated:YES];
[rvController release];
}
}
I figured out my problem, all of my memory leaks stemmed from this statement:
self.stories = [[NSMutableArray alloc] init];
This causes the retain count of stories to be incremented by 2, since the setter calls retain on the newly allocated array.
I replaced the above statement with this one and it solved my problem:
NSMutableArray *array = [[NSMutableArray alloc] init];
self.stories = array;
[array release];
Another way of fixing your code is this replacing
self.stories = [NSMutableArray alloc] init];
with
self.stories = [NSMutableArray arrayWithCapacity:10];
The arrayWithCapacity method is autoreleased so you don't need to manually call release. (This is true for other classes i.e. setWithCapacity, stringWithFormat etc)
Thanks, Sam
PS Not helping your question but these lines look a little unusual :
[self.currentTitle release];
You should probably be doing this :
self.currentTitle = nil;
That will release currentTitle the same as your code does but it will also set it to nil which means you can't use it again by mistake!

Display NSMutableArray in Table View Cell

How could I display arrayData in table view cell?
I want to set the table view cell's label text to the 'ename' from the data parsed.
Please help me out.
Thanks in Advance.
- (void)viewDidLoad {
NSString *url = [NSString stringWithFormat:#"http://mmabigshow.com/app/get_result_from_query.php?q=select * from event"];
NSString *escapedUrl = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[self performSelector:#selector(startParsing:) withObject:escapedUrl afterDelay:1.0];
NSLog(#"View Did Load End");*/
[super viewDidLoad];
}
- (void) startParsing: (NSString *) query{
NSLog(#"Start Of Parsing");
NSURL *xmlURL = [[NSURL alloc] initWithString:query];
NSData *myData = [NSData dataWithContentsOfURL:xmlURL];
NSString *myStr = [[NSString alloc] initWithData:myData encoding:NSWindowsCP1252StringEncoding];
myStr = [myStr stringByReplacingOccurrencesOfString:#"encoding=\"windows-1252\"" withString:#""];
NSData* aData = [myStr dataUsingEncoding:NSUTF8StringEncoding];
rssParser = [[NSXMLParser alloc] initWithData:aData];
[rssParser setDelegate:self];
[rssParser setShouldProcessNamespaces:NO];
[rssParser setShouldReportNamespacePrefixes:NO];
[rssParser setShouldResolveExternalEntities:NO];
[rssParser parse];
NSLog(#"End of Parsing");
}
#pragma mark xml parser
#pragma mark -
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{
currentElement = [elementName copy];
if ([elementName isEqualToString:#"table"]){
item = [[NSMutableDictionary alloc] init];
currentEid = [[NSMutableString alloc] init];
currentEname = [[NSMutableString alloc] init];
currentEurl = [[NSMutableString alloc] init];
dataArray = [[NSMutableArray alloc] init];
}
//NSLog(#"didStartElement");
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{
if ([elementName isEqualToString:#"table"]) {
// save values to an item, then store that item into the array...
[item setObject:currentEname forKey:#"ename"];
//NSLog(#"%#",item);
[dataArray addObject:[[item copy] autorelease]];
//NSLog(#"%#",dataArray);
}
[currentEid release];
[currentEname release];
[currentEurl release];
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{
if ([currentElement isEqualToString:#"eid"]) {
[currentEid appendString:string];
} else if ([currentElement isEqualToString:#"ename"]) {
[currentEname appendString:string];
//NSLog(#"%#",currentEname);
} else if ([currentElement isEqualToString:#"eurl"]) {
[currentEurl appendString:string];
}
// NSLog(#"foundCharacters");
}
#pragma mark -
#pragma mark Table Data Source Methods
- (NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section {
NSLog(#"numberOfRowsInSection");
return [self.dataArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(#"cellForRowAtIndexPath");
static NSString *CustomCellIdentifier = #"CustomCellIdentifier ";
TableDetailsCell *cell = (TableDetailsCell *)[tableView dequeueReusableCellWithIdentifier: CustomCellIdentifier];
if (cell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"TableDetailsCell" owner:self options:nil];
for (id oneObject in nib)
if ([oneObject isKindOfClass:[TableDetailsCell class]])
cell = (TableDetailsCell *)oneObject;
}
NSUInteger row = [indexPath row];
NSDictionary *rowData = [self.dataArray objectAtIndex:row];
//NSLog(#"%#",rowData);
cell.text = [rowData objectForKey:#"ename"];
cell.labelName.text= [rowData objectForKey:#"ename"];
return cell;
}
I believe your problem is that you are not referring to dataArray as self.dataArray all the time which may cause your program not to work properly.
Then assign via
cell.textLabel.text = [self.dataArray objectAtIndex:indexRow.row];
Hope this helped
Seb Kade
"I'm here to help"
Apple's SeismicXML app does exactly this. Look at the rootViewController's cellForRowAtIndexPath.
Also, make sure your tableview has it's delegate and datasource set correctly in Interface Builder (if you chose to use it).