2011-12-22 118 views
0

我使用tableview從json文件填充數組...在我看來控制器我有tableview.when我運行項目我的表視圖編碼不執行。我不知道y?任何人都可以幫助我pls.This是我的視圖控制器文件使用TableView填充數組的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也沒有執行.. – 2011-12-22 06:14:34

+1

我認爲你正在尋找[xSON中的JSON解析](http://sugartin.info/2011/10/19/json-parsing-in -xcode /)。 – 2011-12-22 06:19:33

+0

你一定忘記爲數據源設置委託。 – samfisher 2011-12-22 07:03:11

回答

0

你的問題是你沒有在arraydata對象中的任何數據。它的數量是零。因此,儘管您已設置所有代理&數據源,但您的表委託方法不會調用,因爲它在調用noofrowinSection時將返回零。

請確認您的數組中有數據。

+0

實際上在我的數組即時設置數據從AppDelegate.Before我設置數組值UITableView加載到模擬器。因此,該數組值的返回零,即時通訊沒有得到我的tableview與data.Anyway感謝巴迪...我發現那之前...你是對的! – 2011-12-23 19:26:05

0

你初始化了你的arraydata對象嗎?同時它也會告訴我你沒有爲你的tableview設置委託和數據源,因爲你的nslog委託方法沒有被調用。

+0

我已經初始化了arraydata,並且同時設置了委託和datasource.still我還沒有清除這個問題...即時通訊的其中一個錯誤也是「應用程序預計在應用程序啓動結束時有一個根視圖控制器」 – 2011-12-22 09:09:12

0

這樣做是爲了在你的頭文件中設置tableView的委託和數據源。

@interface JSONparserViewController: UIViewController<UITableViewDelegate,UITableViewDataSource> 

{

}

還要檢查你的arraydata陣列給出內存或not.If不給它的內存第一

0

你有尼特分配您的陣列。首先你必須在你分配數組值的地方分配數組。 NSLog你的陣列在視圖中將出現,如果打印,則必須執行

0

請確認您的數組中有數據。一旦解析完成後,然後重新加載表中的connectiondidfinishloading方法。表將自動重新加載。