Ios 带字典和数组的iPhone阵列(ListApp)

Ios 带字典和数组的iPhone阵列(ListApp),ios,objective-c,nsarray,nsdictionary,Ios,Objective C,Nsarray,Nsdictionary,我正在开发一个列表应用程序。我有两个阵列(动物和汽车)。代码如下所示: 编辑: 这是全新的整体代码。m和您的建议: 现在,一切都在一个列表中是可行的。现在如何在列表中对它们进行分组 #import "ListeViewController.h" @interface ListeViewController () @end @implementation ListeViewController{ NSArray *kategorien; NSArray *autosArr

我正在开发一个列表应用程序。我有两个阵列(动物和汽车)。代码如下所示:

编辑:

这是全新的整体代码。m和您的建议: 现在,一切都在一个列表中是可行的。现在如何在列表中对它们进行分组

#import "ListeViewController.h"

@interface ListeViewController ()

@end

@implementation ListeViewController{

    NSArray *kategorien;
    NSArray *autosArray;
    NSArray *tiereArray;
    NSArray *kategorienArray;
    NSArray *combined;
    NSDictionary *allgemein;

}


-(instancetype) initWithCoder:(NSCoder *)aDecoder{

    self = [super initWithCoder:aDecoder];

    if (self){
        self->kategorien = @[@"Autos", @"Tiere"];
        self->autosArray = @[@"Opel", @"Mercedes", @"Audi"];
        self->tiereArray = @[@"Hamster", @"Ente", @"Schwan", @"Pferd", @"Pinguin"];
        self->combined = [autosArray arrayByAddingObjectsFromArray:tiereArray];
        self->allgemein = [NSDictionary dictionaryWithObjects: combined forKeys:combined];


    }

    return self;
}

-(instancetype) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{

    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

    if (self) {
        self->kategorien = @[@"Autos", @"Tiere"];
        self->autosArray = @[@"Opel", @"Mercedes", @"Audi"];
        self->tiereArray = @[@"Hamster", @"Ente", @"Schwan", @"Pferd", @"Pinguin"];
        self->combined = [autosArray arrayByAddingObjectsFromArray:tiereArray];
        self->allgemein = [NSDictionary dictionaryWithObjects: combined forKeys:combined];

    }

    return self;
}


- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

}

#pragma mark -
#pragma mark Table view data source

-(NSInteger) numberOfSectionsInTableView:(UITableView*) tableView{

    return 1;
}

-(NSInteger)tableView:(UITableView *) tableView numberOfRowsInSection:(NSInteger)section{

    return [combined count];
}

// 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:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
                    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
                        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
                    }
                    }
                    //Configure the Cell

                    cell.textLabel.text = [combined objectAtIndex:indexPath.row];

                    return cell;
                    }



#pragma mark -
#pragma mark Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    NSLog(@"In did Select Row At Index Path");
    NSLog(@"Row %d" ,indexPath.row);

                    }


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
(sry或数组和字典的德语标记,对于某些拼写和语法也是sry)

您可以使用创建基于两个数组的NSDictionary

你会这样做:

self.allgemein = [NSDictionary dictionaryWithObjects:autosArray forKeys:tiereArray];
如果要组合这两个数组,然后使用相同的键和对象将它们存储在字典中(尽管我不确定为什么要这样做),请执行以下操作:


谁教你使用
self->xxx
?您是否研究过属性以及如何使用它们?你为什么需要一本字典?我正在一个小组里开发一个更大的应用程序。这是为了训练,但没人知道如何处理。在更大的应用程序中,我们必须放入广告。广告是用这种类型的字典管理的。好的,谢谢。直到这里我才明白。但是,当“autosArray”和“tiereArray”都是字典和键的数组时,该如何处理呢?我现在是否必须编写
self.allgemein=[NSDictionary Dictionary WithObjects:AutoArray,tiereArray forKeys:AutoArray,tiereArray]?如果我理解正确,您正在尝试创建一个字典,其中键是tiereArray,对象是autosaray?i、 e.:@{“仓鼠”=>@“欧宝”、@“恩特”=>@“梅赛德斯”…}如果您试图创建一个键和对象相同且同时包含tiereArray和AutoArray的字典,请参见我编辑的答案。thx。第一个问题已经解决。现在另一个(请看我的编辑)。按什么分组?您是否可以编辑您的问题以显示您希望数据的外观?
NSArray *combined = [self.autosArray arrayByAddingObjectsFromArray:self.tiereArray];
self.allgemein = [NSDictionary dictionaryWithObjects:combined forKeys:combined];