-1

我想从UITableView尝试将搜索到的对象从一个数组添加到另一个数组时进行搜索,我的应用程序崩溃了。这是我尝试将对象从一个数组添加到另一个数组的代码。 searchedContactsFromTableNSMutableArray.in 我得到 200 个对象。

    NSMutableArray *searchArray = [[NSMutableArray alloc] init];
for (NSDictionary *dictionary in searchedContactsFromTable)
{
       NSArray *array = [dictionary objectForKey:@"fullName"];
       [searchArray addObjectsFromArray:array];

}

如何添加数组?

4

4 回答 4

1

假设你searchedContactsFromTable是这样的:

searchedContactsFromTable :: (
        {
        fullName =         {
            fName = Abc;
            lName = Ghi;
            mName = Def;
        };
    }
)

你想要这样的输出:

searchArray :: (
        (
        Abc,
        Ghi,
        Def
    )
)

您的代码应该是:

    NSMutableArray *searchArray = [[NSMutableArray alloc] init];
    for (NSDictionary *dictionary in searchedContactsFromTable)
    {
        NSDictionary *dict = [dictionary objectForKey:@"fullName"];
        [searchArray addObject:[dict allValues]];
    }
于 2013-01-22T07:08:38.030 回答
0
NSMutableArray *searchArray = [[NSMutableArray alloc] init];
for (NSDictionary *dictionary in searchedContactsFromTable)
{
       NSMutableArray *array = (NSMutableArray *)[[[dictionary objectForKey:@"fullName"] miutableCopy];
       [searchArray addObjectsFromArray:array];

}
于 2013-01-22T06:06:57.773 回答
0

试试这个 :

NSMutableArray *array = [[NSMutableArray alloc] init];
NSMutableArray *searchArray = [[NSMutableArray alloc] init];
for (NSDictionary *dictionary in searchedContactsFromTable)
{
       [array addObject:[dictionary objectForKey:@"fullName"]];
       [searchArray addObjectsFromArray:array];

}
于 2013-01-22T07:08:11.687 回答
0

只是改变 :

NSMutableArray *searchArray = [[NSMutableArray alloc] init];
for (NSDictionary *dictionary in searchedContactsFromTable)
{
       NSString *array = [dictionary objectForKey:@"fullName"];
       [searchArray addObject:array];

}

作为你在这里得到的数组变量不是一个数组,而是一个字符串。

于 2013-01-22T07:50:45.473 回答