如何获得添加了int值的UIView数组?

时间:2012-10-22 11:57:02

标签: ios cocoa-touch uiview

所以我试图添加一个带有UIView的数组作为整数的值。例如,如果我的整数值为5,我希望数组添加视图5次,如果整数值变为7,则将其添加7次。我很确定这是可能的;我尝试了几种方法,后来没有成功地将UIView作为一个视图数组添加。它只是添加了相同的视图,这将在应用程序中创建一个错误。我的代码并没有真正帮助解释我不认为,但我会发布它只是 帮助。我应该提一下,只要编辑了我从中提取值的服务器,整数值就会改变:

int numObjectives;
    NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@/api/groups/get/1",URL_ROOT]];

    NSData *data = [NSData dataWithContentsOfURL:url];

        NSError *error = nil;
        NSDictionary *result = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error];
        if (error == nil) {
            NSLog(@"%@", result);
// Collecting data from server and logging the results to make sure it's working.

            NSDictionary *user_results = [result objectForKey:@"results"];
            NSString *name = [user_results objectForKey:@"name"];
//n_obj is the number of objectives displayed on the server
            NSString *n_obj = [user_results objectForKey:@"n_objectives"];
            NSLog(@"%@", n_obj);
//numObjectives is my int which is equal to whatever the String n_obj is on the server.
            numObjectives = [ n_obj integerValue];

所以现在我发布了一些代码,我只是总结一下我想做的事情。我希望我的UIView添加numObjectives值的次数相同。我认为最好的方法是为UIView创建一个数组,这样不仅仅是不断地添加UIView,而不是Xcode友好的方式。希望我发布的代码有助于理解我正在尝试做的事情。对不起,如果我没有很好地解释这一点,我很乐意在必要时详细说明。在此先感谢家伙和女孩!

0 个答案:

没有答案