2011-12-22 164 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方法。表将自动重新加载。