首页 文章

如何在iOS核心数据中添加json解析数据?

提问于
浏览
0

这是我的数据解析代码解析完成 . 如何在核心数据中添加该数据

NSError * error = [请求错误]; NSString * responseString = nil;

if(!error){responseString = [request responseString];

SBJsonParser *parser = [[SBJsonParser alloc] init] ;

NSMutableArray *jsondata = [parser objectWithString:responseString];
NSMutableArray *jsondata1 = [[NSMutableArray alloc]init];

for(int i=0;i<jsondata.count;i++)
{

    info *myinfo=[[info alloc]init];
    myinfo.Id=@"Id";
    myinfo.Name=@"Name";
    myinfo.IsActive=@"IsActive";

    [jsondata1 addObject:myinfo];
     NSLog(@"%@",responseString);

}

   for(int i=0;i<jsondata1.count;i++)
   {
   info *myinfo= [jsondata1 objectAtIndex:i];

   [jsondata1 addObject:myinfo];

    }

1 回答

  • 1

    您可以使用它的最简单方法是 -

    int yPossion = 50, xPossion = 10; int temp = 0;
    UIScrollView *scrollView = [[UIScrollView alloc]initWithFrame:self.view.frame];
    [self.view addSubview:scrollView];
    for (int i = 0; i<50; i++){
        UIButton *aButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [aButton setBackgroundColor:[UIColor blackColor]];
        [aButton setBackgroundImage:[UIImage imageNamed:@"icon-menu.png"] forState:UIControlStateNormal];
    
        [aButton setTitle:[NSString stringWithFormat:@" %d",i] forState:UIControlStateNormal];
        [aButton setFrame:CGRectMake(xPossion, yPossion, 100, 50)];
    
        [scrollView addSubview:aButton];
        xPossion += aButton.frame.size.width+15;
        temp++;
        if (temp==3) {
            yPossion = aButton.frame.origin.y+aButton.frame.size.height+15;
            temp = 0;
            xPossion = 10;
            [scrollView setContentSize:CGSizeMake(scrollView.frame.size.width, yPossion+50)];
        }
    }
    

    但是如果你想使用autoLayout约束它,那么你可以按照这个link它可能会帮助你 .

相关问题