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

发布于 2024-11-26 13:19:49 字数 1783 浏览 1 评论 0原文

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

我希望将我的数据存储在

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 代码的框架,因为仅在 fetchng 中面临问题

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

I am trying store records in UITableView each cell on reload data from a form. For this when user press add button so so multiple labels should be added to 1st indexPath then on reclicking add button again multiple cells must be added to second cell retaining first.

I am looking to store my data in

MyArray ({
  firstindex: 1st record
  firstindex: 2nd record
}
{
  secondindex : 1st record
  secondindex : 2nd record
})

Records are comming from UITextView and saving into table on each Add button click on each row with multiple entries

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

I have implemented through this way but showing repeated data on TableView Cell, I am not including frame of UILabel code, as only facing problem in fetchng

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

烂人 2024-12-03 13:19:49

尝试像您的方法中那样检索一次数组

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

}

Try to retrieve the array once like in your methos

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

}
灯角 2024-12-03 13:19:49

解决方案,因为 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];

这对我有用

Solution as NSMutableDictionary is overriding the content I dont know why so I allocated it within the function

    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];

This works for me

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文