我创建了一个应用程序,它将从Web服务中获取信息。到目前为止,我通过使用NSLog显示内容来获取它,但是当我尝试将其加载到UITableViewCell中时,它不显示。这里是我的对于UItbaleview iOS中未显示单元格json内容
#import "TableViewController.h"
#import "JSON.h"
#import "SBJsonParser.h"
@interface TableViewController()
@end
@implementation TableViewController
@synthesize jsonurl,jsondata,jsonarray;
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
}
jsonurl=[NSURL URLWithString:@"http://minorasarees.com/category.php"];
jsondata=[[NSString alloc]initWithContentsOfURL:jsonurl];
self.jsonarray=[jsondata JSONValue];
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [jsonarray count];
}
- (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];
}
NSLog(@"1");
NSLog(@"%@",jsonarray);
cell.textLabel.text=[jsonarray objectAtIndex:indexPath.row];
NSLog(@"2");
return cell;
}
-(void)dealloc
{
[super dealloc];
[jsonarray release];
[jsondata release];
[jsonurl release];
}
@end
我已通过添加与UITableViewController..will文件,该文件是一个problem..Help请插入tableviewcontroller代码..
你记录了“[jsonarray objectAtIndex:indexPath.row]”吗? – 2012-07-22 07:30:07
ya.I可以让我的json内容在[jsonarray objectAtIndex:indexPath.row] .. – Dany 2012-07-22 07:34:11
你可以通过设置文本“cell.textLabel.text = @”test“;”? – 2012-07-22 07:36:25