我創建了一個應用程序,它將從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