2012-07-22 3 views
0

웹 서비스에서 정보를 가져올 응용 프로그램을 만들었습니다. 지금까지는 NSLog를 사용하여 내용을 표시했지만 UITableViewCell에서로드하려고 시도했을 때 표시되지 않았습니다. 여기에 있습니다. 당신이 설정하는 그래서이 problem..Help주세요 UITableViewController..will에 파일을 추가하여 tableviewcontroller를 삽입 한 그UItbaleview 셀 JSON 내용이 iOS에 표시되지 않음

#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 

에 대한 코드는 ...

+0

"[jsonarray objectAtIndex : indexPath.row]"를 기록 했습니까? –

+0

예. [jsonarray objectAtIndex : indexPath.row]에서 json 컨텐츠를 얻을 수 있습니다 .. – Dany

+0

"cell.textLabel.text = @"test ";"로 텍스트를 설정할 수 있습니까? –

답변

2

귀하의 JSON은, 사전의 배열을 포함 테이블보기의 텍스트는 문자열이 예상되기 때문에 작동하지 않는 사전에 셀을 표시합니다. 이것은 실제로 충돌해야합니다. 당신이 당신의 dealloc 방법으로 호출 할 수있는 마지막 일이 될 필요가 [super dealloc] : 코드 잘못 다른 일이 있습니다이 외에

cell.textLabel.text=[[jsonarray objectAtIndex:indexPath.row] valueForKey: @"category"]; 

:

는 그 사전의 범주 속성에 텍스트를 설정 해결합니다. 그리고 당신은 정말로 비동기 네트워킹 코드를 사용해야합니다. 네트워킹으로 메인 스레드를 차단하는 것은 용납되지 않습니다.

+0

큰 도움을 주셔서 감사합니다 ...이 작품 ... – Dany

+0

카테고리, 제목, 아이디와 같은 사전 값 이상을 가지고있는 경우에 대비해서 ... 나는 그것을 모두 표시해야합니다. 단일 셀에서 ... 내가 어떻게 그것을 얻을 수 있습니까? – Dany

+0

'([NSString stringWithFormat :]'를 사용하여) 모두 포함하는 단일 문자열을 작성하거나 여러 레이블을 포함하는 사용자 정의 테이블보기 셀을 작성하십시오. – Sven