2011-12-22 26 views
0

テーブルビューを使用してjsonファイルから配列を取り込む...私のビューのコントローラでは、私はテーブルビューのコードを実行していないtableview.whenを持っています。誰も私を助けpls.Thisは私のviewcontrollerファイルですJSONを使用してテーブルビューを使用して配列を作成する

#import "JSONparserViewController.h" 
    @implementation JSONparserViewController 
    @synthesize arraydata; 

    - (void)didReceiveMemoryWarning 
    { 
     [super didReceiveMemoryWarning]; 
     // Release any cached data, images, etc that aren't in use. 
    } 


    #pragma mark - View lifecycle 

    - (void)viewDidLoad 
    { 
     [super viewDidLoad]; 
     // Do any additional setup after loading the view, typically from a nib.  
    } 


    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
     NSLog(@"No Of Elements in Array Data: %d",[arraydata count]); 
     return [arraydata count]; 
} 

    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
    { 
     return 80; 
    } 


    // Customize the appearance of table view cells. 
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

     static NSString *CellIdentifier = @"Cell"; 

     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
     if (cell == nil) { 
      cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]; 
     } 

     // Configure the cell... 
     NSLog(@"%@",arraydata); 
     NSDictionary *aTweet = [arraydata objectAtIndex:[indexPath row]]; 
     cell.textLabel.text = [aTweet objectForKey:@"name"]; 
     // NSDictionary *newArray=[aTweet objectForKey:@"properties"]; 
     // 
     // NSDictionary *newArray1=[newArray objectForKey:@"propertyMeta"]; 
     // cell.detailTextLabel.text = [newArray1 objectForKey:@"name"]; 
     // cell.detailTextLabel.text = [newArray objectForKey:@"value"]; 
     cell.textLabel.adjustsFontSizeToFitWidth = YES; 
     cell.textLabel.font = [UIFont systemFontOfSize:12]; 
     cell.textLabel.minimumFontSize = 10; 
     cell.textLabel.numberOfLines = 4; 
     cell.textLabel.lineBreakMode = UILineBreakModeWordWrap; 

     //cell.detailTextLabel.text = [newArray1 objectForKey:@"type"]; 

     // NSURL *url = [NSURL URLWithString:[aTweet objectForKey:@"profile_image_url"]]; 
     // NSData *data = [NSData dataWithContentsOfURL:url]; 
     // cell.imageView.image = [UIImage imageWithData:data]; 
     cell.selectionStyle = UITableViewCellSelectionStyleNone; 
     NSLog(@"HIIIIIIIIII"); 
     return cell; 

    } 
+0

上記のコードでは、NSLogも実行されていません。 –

+1

あなたは[JSONのxCodeの解析]を探していると思います(http://sugartin.info/2011/10/19/json-parsing-in -xcode /)。 –

+0

データソースのデリゲートを設定するのを忘れている必要があります。 – samfisher

答えて

0

あなたの問題はarraydataオブジェクトにはありません。その数はゼロです。したがって、すべてのデリゲート&データソースを設定しても、noofrowinSectionを呼び出すときにゼロを返すため、テーブルデリゲートメソッドは呼び出されません。

arrayObjectにデータがあることを確認してください。

+0

私の配列では、AppDelegate.Beforeからデータを設定する私は配列値をシミュレータにロードされた配列値を設定します。その配列値は0を返し、data.Anywayで私のtableviewを取得していない私は直前に見つけた...あなたは正しい! –

0

arraydataオブジェクトを初期化しましたか?また、nslogデリゲートメソッドが呼び出されていないテーブルビューbecozのデリゲートとデータソースを設定していないことがわかります。

+0

私はすでにarraydataを初期化しており、デリゲートとdatasource.stillの両方を設定しています。この問題を解決するには... "アプリケーションの起動時にルートビューコントローラが必要です"というエラーもあります。 –

0

ヘッダーファイルにtableViewのデリゲートとデータソースを設定するには、これを行います。

@interface JSONparserViewController: UIViewController<UITableViewDelegate,UITableViewDataSource> 

{

}

また、あなたのarraydata配列がメモリを与えたり、あなたの配列を割り当てるNITている、それをメモリ最初

0

を与えないnot.Ifされていることを確認してください。まず、配列値を代入するときはいつでも配列を割り当てなければなりません。 NSLogあなたの配列が表示されたら、表示されたら実行する必要があります。

0

ご使用のアレイにデータがあることを確認してください。そして、解析が完了したら、connectiondidfinishloadingメソッドでテーブルをリロードします。テーブルは自動的にリロードされます。

関連する問題