【问题标题】:how to add json parse data in core data in iOS?如何在iOS的核心数据中添加json解析数据?
【发布时间】:2014-11-24 18:52:11
【问题描述】:

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

-(void)DataRetireve { deatilinfoarray = [[NSMutableArray alloc] init]; NSURL *url = [NSURL URLWithString:@"http://sms.instatalkcommunications.com/apireq/GetSMSCategories?t=1&h=admin&param=1"]; ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url]; [请求 setDelegate:self]; [请求启动异步]; }

  • (void)requestFinished:(ASIHTTPRequest *)request {

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

    如果(!错误) { 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];
    
        }
    

【问题讨论】:

  • 在这些情况下,您通常使用UICollectionView
  • 我肯定会得到 Paint Code 这样的东西。如果你还不是瘾君子,paintcodeapp.com。我是唯一的飞行方式 - 做一次,永远不要再做

标签: ios objective-c autolayout


【解决方案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 可能会对你有所帮助。

【讨论】:

  • 如何为每个按钮设置标签,例如愤怒的 ams、love ams 等等
  • @chetangharat 设计这种视图的最佳方式是使用 UICollectionView。你可以找到 Ray Wender Lich 教程raywenderlich.com/22324/… 来使用它。
  • @chetangharat 使用 UICollectionView,您将在设计、搜索和所有方面拥有很大的灵活性。它将帮助您创建所需的网格。
  • 我使用 int count=20; for(int i = 0; i
  • 我知道,但我必须动态(以编程方式)创建所有控件,所以不能使用拖放控件。我问你。
猜你喜欢
  • 2012-08-24
  • 1970-01-01
  • 2013-06-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-12-31
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多