如何在View控制器中显示来自JSON的数据

时间:2016-04-07 07:30:11

标签: ios objective-c iphone json

我知道如何通过index.row在单元格UITableViewController中显示数据,但我不知道如何在viewController中显示数据

例如。

当我使用UITableViewController时,

  

NSString * str = [NSString stringWithFormat:@"%@",[[self.data   objectAtIndex:indexPath.row] valueForKey:@" profile_image"]]; //数据   是我的阵列

此代码将从数组中获取图像,并在index.row。

的帮助下将其设置在特定单元格中

但是当我使用UIViewController时,我应该如何为特定视图设置数据?

请向我提供有关此问题的指导,我如何将图像表单数组设置为我的ViewController,因为我将UITableViewController设置为objectAtIndex:indexPath.row

由于

1 个答案:

答案 0 :(得分:1)

i asked the above question but i got answer myself after many research and defiantly with the help of my stackoverflow's intelligent friends.

so i like to post my answer.

my answer is if i take int value i and then i use it in my function then it look like below code..

  [requestDynamic startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {

       // Insert your code here

        NSLog(@"%@",result);
        self.arrData = nil;
        self.arrData = [[NSMutableArray alloc]init];
        self.arrData = [result[@"data"] mutableCopy];


        int i =0;
//        NSString *strImage1 = [NSString stringWithFormat:@"%@",[[self.arrData objectAtIndex:i]valueForKey:@"picture"]];
        NSString *strComment =[NSString stringWithFormat:@"%@", [[self.arrData objectAtIndex:i ]valueForKey:@"message"]];
        NSString *strLike = [NSString stringWithFormat:@"%@", [[[[self.arrData objectAtIndex:i]valueForKey:@"likes"]valueForKey:@"summary"]valueForKey:@"total_count"]];
        NSString *strCommentCount = [NSString stringWithFormat:@"%@", [[[[self.arrData objectAtIndex:i]valueForKey:@"comments"]valueForKey:@"summary"]valueForKey:@"total_count"]];


        CustomSocialView *imageView1 = [[CustomSocialView alloc] initWithFrame:CGRectMake(0, 0, width, height)];
        [imageView1 setContentText:strComment like:strLike comment:strCommentCount];

may be this question and answer is silly for you all experienced people but it is very important for me and some others like me.

so i post answer as i got it.

Thank you