请允许任何人纠正我的愚蠢错误,因为我无法将解析后的XML显示在Table视图中。
我希望我的标签显示在表格视图上。 这是我的代码(忽略我的语法......因为我无法在这里正确粘贴它)....
要分配的XML
<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
答案 0 :(得分:1)
array
包含课程NSString
的对象:[array addObject:@"mAc"];
cell.textLabel.text = [array objectAtIndex:indexPath.row];
答案 1 :(得分:1)
你喜欢这个,
book.arrayString= [array objectAtIndex:indexPath.row];
这也显示了您自己添加的数据(即)mAc,Mayank等等。
否则你可以添加像
这样的值Cell.textLabel.text=[array objectAtIndex:indexPath.row];