如何在 iPhone 中的 NSMutableArray 中创建 NSDictionary?
我有一个 NSMutableDictionary,它包含用户详细信息。我已经使用解析并从 MutableDictionary 获取数据。
feedDictionary 是, {
"city = New York",
"phone = 111111",
"email = [email protected]",
"year = 1986",
"degree = Undergraduate"
}
我已将所有值添加到 FeedArray 中,并且我想为 FeedArray 创建两个字典。因为我已在节表视图中显示数据。因此表部分数据为 - 第 1 部分 - [城市,电话,电子邮件] 和第 2 部分 - [年份,学位]。因为如果数据中的任何一个为零,那么我不应该删除该部分中的特定行。所以我想检查数据,数据是否为零。
编辑:
在添加到 FeedArray 之前,我想检查字符串是否为零。如果字符串为零,那么我不应该添加数组,如果数据不为零,则只添加到 FeedArray 中。
[self isEmpty:[feedDictionary valueForKey:@"city"]]?:[feedArray addObject:[feedDictionary valueForKey:@"city"]]; //section1
[self isEmpty:[feedDictionary valueForKey:@"phone"]]?:[feedArray addObject:[feedDictionary valueForKey:@"phone"]]; //section1
[self isEmpty:[feedDictionary valueForKey:@"email"]]?:[feedArray addObject:[feedDictionary valueForKey:@"email"]]; //section1
[self isEmpty:[feedDictionary valueForKey:@"year"]]?:[feedArray addObject:[feedDictionary valueForKey:@"year"]]; //section2
[self isEmpty:[feedDictionary valueForKey:@"degree"]]?:[feedArray addObject:[feedDictionary valueForKey:@"degree"]]; //section2
-(BOOL) isEmpty :(NSString*)str{
if(str == nil || [[str stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] length] == 0)
return YES;
return NO;
预期输出
是,
我的数组是 5 (
section1{
"city = New York",
"phone = 111111",
"email = [email protected]",
}
section2
{
"year = 1986",
"degree = Undergraduate"e"
}
) 那么我如何为可变数组创建字典。所以请指导我。
谢谢!
I have one NSMutableDictionary and it contains the user details. I have used parsing and get the data from the MutableDictionary.
feedDictionary is,
{
"city = New York",
"phone = 111111",
"email = [email protected]",
"year = 1986",
"degree = Undergraduate"
}
I have added all the value into the FeedArray and i want to create the two dictionary for the FeedArray.Because i have displayed the data in the section table view. so the table section data is - Section-1 -[city,phone,email] and Section-2-[year,degree]. Because if the anyone of the data is nil, so i shouldn't remove that particular rows in that section. so that i want to check the data, whether the data is nil or not.
Edit:
Before i added to the FeedArray, i want to check the string is nil or not. If the string is nil, then i shouldn't add the Array and if the data is not nil, then only added to the FeedArray.
[self isEmpty:[feedDictionary valueForKey:@"city"]]?:[feedArray addObject:[feedDictionary valueForKey:@"city"]]; //section1
[self isEmpty:[feedDictionary valueForKey:@"phone"]]?:[feedArray addObject:[feedDictionary valueForKey:@"phone"]]; //section1
[self isEmpty:[feedDictionary valueForKey:@"email"]]?:[feedArray addObject:[feedDictionary valueForKey:@"email"]]; //section1
[self isEmpty:[feedDictionary valueForKey:@"year"]]?:[feedArray addObject:[feedDictionary valueForKey:@"year"]]; //section2
[self isEmpty:[feedDictionary valueForKey:@"degree"]]?:[feedArray addObject:[feedDictionary valueForKey:@"degree"]]; //section2
-(BOOL) isEmpty :(NSString*)str{
if(str == nil || [[str stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] length] == 0)
return YES;
return NO;
}
Expected output is,
My array is 5 (
section1{
"city = New York",
"phone = 111111",
"email = [email protected]",
}
section2
{
"year = 1986",
"degree = Undergraduate"e"
}
)
So how can i create the dictionary for the Mutable Array. So Please guide me.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的 UITableView 数据源方法:
编辑:我想我误解了你编辑的问题。你的代码乍一看看起来不错。
your UITableView Datasource methods:
Edit: I guess i misunderstood your edited question. your code looks fine at first sight.