-1

我在这段代码中有一个错误

NSString *str = @"above string"; //load above string here
NSArray * firstArry = [str componentsSeparatedByString:@"#"];
NSMutableArray *secondArry = [[NSMutableArray alloc] init]; //Will hold the # titles
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init]; //Will hold the strings related to # title
for(NSString firstArryStr : firstArry)
{
    NSArray *tempArry = [firstArryStr componentsSeparatedByString@"\n"];
    NSMutableArray *titleStingsArry = [[NSMutableArray alloc] init];
    for (int i=0; i< [tempArry count];i++)
    {
        if (i==0)
        {
            NSString *title = [tempArry  objectAtIndex:i];
            [secondArry addObject:title];
            [dict setValue:titleStingsArry  forKey:title];
        } else {
            [titleStingsArry  addObject:[tempArry  objectAtIndex:i]];
        }
    } 
 }

错误出现在第一个“for”上。

这是处理该问题的代码:

# 2012
20120604 Huge Sandstorm over Saudi Arabia
20120527 Huge Sandstorm over niger
# 2012
20110330 Huge Sandstorm over niger
# just for the test
20110330 AHuge Sandstorm over niger
20110330 BHuge Sandstorm over niger
20110330 CHuge Sandstorm over niger
20110330 1Huge Sandstorm over niger
20110330 2Huge Sandstorm over niger
20110330 3Huge Sandstorm over niger
20110330 4Huge Sandstorm over niger
20110330 5CHuge Sandstorm over niger
20110330 6Huge Sandstorm over niger
# **********
20110330 7Huge Sandstorm over niger
20110330 8Huge Sandstorm over niger
20110330 9CHuge Sandstorm over niger
20110330 AHuge Sandstorm over niger
20110330 B10CHuge Sandstorm over niger
20110330 **CHuge Sandstorm over niger

在一个UITableView不同的部分,其中标题将是# .......和内容20110330 ........ 20110330 ........ 20110330 ........

有人可以帮我吗?

4

2 回答 2

7

使用 for 方法是...

for(NSString *firstArryStr in firstArry)
{

             //Put your all code here 
}

希望这能解决您的问题

于 2012-06-13T13:45:47.920 回答
2

采用:

for(NSString *str in firstArry)
于 2012-06-13T13:46:42.730 回答