在 NSMutableArray 中的 NSDictionary 中显示 tableView 中的数据
我正在尝试在从表单重新加载数据时将记录存储在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试像您的方法中那样检索一次数组
Try to retrieve the array once like in your methos
解决方案,因为 NSMutableDictionary 正在覆盖内容,我不知道为什么,所以我在函数中分配了它,
这对我有用
Solution as NSMutableDictionary is overriding the content I dont know why so I allocated it within the function
This works for me