Iphone 在NSMutableArray中的NSDictionary的tableView中显示数据

Iphone 在NSMutableArray中的NSDictionary的tableView中显示数据,iphone,objective-c,arrays,dictionary,Iphone,Objective C,Arrays,Dictionary,在从表单重新加载数据时,我尝试将记录存储在UITableView的每个单元格中。为此,当用户按下“添加”按钮时,应将多个标签添加到第一个indexPath,然后再次单击“添加”按钮时,必须将多个单元格添加到第一个保留的第二个单元格 我希望将我的数据存储在 MyArray ({ firstindex: 1st record firstindex: 2nd record } { secondindex : 1st record secondindex : 2nd record })

在从表单重新加载数据时,我尝试将记录存储在UITableView的每个单元格中。为此,当用户按下“添加”按钮时,应将多个标签添加到第一个indexPath,然后再次单击“添加”按钮时,必须将多个单元格添加到第一个保留的第二个单元格

我希望将我的数据存储在

MyArray ({
  firstindex: 1st record
  firstindex: 2nd record
}
{
  secondindex : 1st record
  secondindex : 2nd record
})
记录从UITextView提交并保存到表中。在每个添加按钮上,单击具有多个条目的每一行

- (IBAction) Add
{
      [myDict setObject:countryTxt.text forKey:@"Country"];
        [myDict setObject:cityTxt.text forKey:@"City"];
        [myDict setObject:EscortsNumTxt1.text forKey:@"people"];
        [myDict setObject:fromDate.text forKey:@"Datetogo"];
        [myDict setObject:toDate.text forKey:@"Datetoreach"];

        [moreArr addObject:myDict];

        NSLog(@"moreDict %@",moreArr);

        numberOfrows++;

        [moreTable reloadData];
}
我已经通过这种方式实现了,但在TableView单元格上显示了重复的数据,我并没有包括UILabel代码的框架,因为我只是在获取时遇到了问题

- (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] autorelease]; 
}

countrylbl.text = [[moreArr objectAtIndex:indexPath.row] objectForKey:@"Country"];
        citylbl.text = [[moreArr objectAtIndex:indexPath.row] objectForKey:@"City"];
        people.text = [[moreArr objectAtIndex:indexPath.row] objectForKey:@"people"];
        toDateLbl.text = [[moreArr objectAtIndex:indexPath.row] objectForKey:@"Datetogo"];
        fromDteLbl.text = [[moreArr objectAtIndex:indexPath.row] objectForKey:@"Datetoreach"];
}

尝试检索数组一次,就像在Methods中一样

- (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] autorelease]; 
    }


    NSArray *results = [[NSArray alloc] initWithArray:[moreArr objectAtIndex:indexPath.row]];

    NSLog("%@",results); //Check that everything is in the right place

    // DO STUFF

    [results release];

}

解决方案,因为NSMutableDictionary覆盖了内容,我不知道为什么,所以我在函数中分配了它

    moreTableDict = [[NSMutableDictionary alloc] init];

    [myDict setObject:countryTxt.text forKey:@"Country"];
    [myDict setObject:cityTxt.text forKey:@"City"];
    [myDict setObject:EscortsNumTxt1.text forKey:@"people"];
    [myDict setObject:fromDate.text forKey:@"Datetogo"];
    [myDict setObject:toDate.text forKey:@"Datetoreach"];

    [moreArr addObject:myDict];

这对我有效

您的示例完全缺少表实现(这是您问题的核心部分)。我也添加了我的UITableView代码。这对我无效,因为它正在崩溃,尽管我自己已经解决了问题,解决方案发布在下面