使用 Tableview 填充 JSON 数组

发布于 2024-12-22 13:46:47 字数 2608 浏览 4 评论 0原文

我正在使用 tableview 从 json 文件填充数组...在我的视图控制器中,我有 tableview。当我运行该项目时,我的表视图编码没有执行。我不知道你?有人帮助我吗?这是我的 viewcontroller 文件

#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;

    }

I m using tableview to populate an array from json file...In my view Controller i have tableview.when i run the project my table view codings are not executing.i dont know y?anyone help me pls.This is my viewcontroller file

#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;

    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

四叶草在未来唯美盛开 2024-12-29 13:46:47

您的问题是 arraydata 对象中没有任何数据。它的计数为零。所以虽然你已经设置了所有 delegate & datasource,您的表委托方法将不会被调用,因为当它调用 noofrowinSection 时,它返回零。

请验证您的 arrayObject 中是否有数据。

Your Problem is you dont have any data in the arraydata object. Its count is zero. So Although you have set all delegate & datasource, Your table delegate methods will not called, because when it calls noofrowinSection, it returns zero.

Please verify that you have data in your arrayObject.

花辞树 2024-12-29 13:46:47

您初始化了 arraydata 对象吗...?而且在我看来,您还没有为 tableview 设置委托和数据源,因为您的 nslog 委托方法没有被调用。

have you initialized your arraydata object...? and also it looks to me that you haven't set the delegate and datasource for your tableview becoz of which your nslog delegate methods are not being called.

七禾 2024-12-29 13:46:47

执行此操作可在头文件中设置 tableView 的委托和数据源。

@interface JSONparserViewController: UIViewController<UITableViewDelegate,UITableViewDataSource>

{

}

还要检查您的 arraydata 数组是否分配了内存。如果没有,请先分配内存

Do this to set the delegate and datasource of tableView in your header file.

@interface JSONparserViewController: UIViewController<UITableViewDelegate,UITableViewDataSource>

{

}

Also check that your arraydata array is given memory or not.If not give it the memory first

失退 2024-12-29 13:46:47

你没有分配你的数组。首先,无论您在何处分配数组值,都必须分配数组。 NSLog 视图中的数组将出现,如果打印则必须执行

you have nit allocate your array. firstly you have to allocate your Array wherever you assign your array value . NSLog your array in view will appear if printed then it must be executed

无悔心 2024-12-29 13:46:47

请验证您的数组中有数据。解析完成后,然后在 connectiondidfinishloading 方法中重新加载表。表将自动重新加载。

Please verify you have data in your array. And once after parsing is done, then reload the table in connectiondidfinishloading method. Table will be automatically reload.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文