开发者

i am unable to display an parsed xml on table view :(

Please can any one correct my silly mistake as i am unable to show my parsed XML to the Table view.

I want my tag to be displayed on table view. here is my code (ignore my syntax ... as i am unable to paste it correctly here)....

XML TO BE PARSED

开发者_如何学运维
<Table><category><Name>Books</Name><cid>2</cid><Logo>http://litofinter.es.milfoil.arvixe.com/Thumbnail/5.png</Logo><Product><pid>55</pid><Title>Un producto para cada necesidad</Title><Thumbnail>http://litofinter.es.milfoil.arvixe.com/Thumbnail/Book3.png</Thumbnail><pdf>http://litofinter.es.milfoil.arvixe.com/PDF/Book6.pdf</pdf></Product><Product><pid>58</pid><Title>Quitamanchas pistola</Title><Thumbnail>http://litofinter.es.milfoil.arvixe.com/Thumbnail/Book9.png</Thumbnail><pdf>http://litofinter.es.milfoil.arvixe.com/PDF/Book7.pdf</pdf></Product></category></Table>

CODE

#TABLEVIEWCONTROLLER.H:


@class Book;

@interface TableViewController : UIViewController<UITableViewDataSource,UITableViewDelegate> {

    IBOutlet UIButton *btnBack;
    IBOutlet UITableView *tableView;
    Book *bookOne;
    NSMutableArray *array;
}

-(IBAction)onTapBack;

@property (nonatomic, retain)IBOutlet UITableView *tableView;


@end

#TABLEVIEWCONTROLLER.M

import "TableViewController.h"
import "XMLTableAppDelegate.h"
import "Book.h"

@implementation TableViewController


@synthesize tableView;

-(IBAction)onTapBack
{
    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Message from mAc" message:@"Trail" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok",nil];
    [alert show];
}


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

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

    UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    cell.selectionStyle = UITableViewCellSelectionStyleBlue;
    Book *book = [[Book alloc]init];
    book = [array objectAtIndex:indexPath.row];

    cell.textLabel.text = book.arrayString;
    [book release]; 
    [cell autorelease];
    return cell;
}


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];

    tableView.delegate = self;
    tableView.dataSource = self;

    //bookOne = [[Book alloc]init];
    array = [[NSMutableArray alloc]init];
    [array addObject:@"mAc"];
    [array addObject:@"Mayank"];
    [array addObject:@"Manu"];

}

-(void)viewWillAppear:(BOOL)animated{

    [tableView reloadData];
}



- (void)dealloc {
    [super dealloc];
    [tableView release];
    [btnBack release];
}

#BOOK.h


@interface Book : NSObject {


    NSMutableString *arrayString;

}

@property(nonatomic,retain) NSMutableString *arrayString;

@end

#BOOK.M

import "Book.h"


@implementation Book

@synthesize arrayString;

-(void)dealloc
{
    [super dealloc];

    [arrayString release];
}

@end


  1. You shouldn't alloc+init memory for Book and don't release it : [book release];
  2. Your array contains objects of class NSString : [array addObject:@"mAc"];
  3. Try to set value using next line: cell.textLabel.text = [array objectAtIndex:indexPath.row];


You do like this,

book.arrayString= [array objectAtIndex:indexPath.row];

This also shows the data you added by your own (ie) that mAc,Mayank and something.

Otherwise You diectly add the value like

Cell.textLabel.text=[array objectAtIndex:indexPath.row];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜