Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/98.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 保存在动态表格内的文本框中输入的文本_Ios_Objective C_Uitableview_Uitextfield - Fatal编程技术网

Ios 保存在动态表格内的文本框中输入的文本

Ios 保存在动态表格内的文本框中输入的文本,ios,objective-c,uitableview,uitextfield,Ios,Objective C,Uitableview,Uitextfield,我是iOS编程新手,我想将输入的文本保存在一个文本框中,该文本框放置在一个动态表格单元格中,表格单元格的内容类似于手风琴 在视图控制器表视图中使用了3个动态原型单元,每个单元分别命名为header、regular和selected,在视图控制器中我使用了以下代码 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCe

我是iOS编程新手,我想将输入的文本保存在一个文本框中,该文本框放置在一个动态表格单元格中,表格单元格的内容类似于手风琴

在视图控制器表视图中使用了3个动态原型单元,每个单元分别命名为header、regular和selected,在视图控制器中我使用了以下代码

 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell * cell = nil;

switch (indexPath.row) {
    case 0:
    {
        cell = [tableView dequeueReusableCellWithIdentifier:@"Header"];
    }
        break;
    default:
    {
        NSArray * innerData = [self.data objectAtIndex:indexPath.row - 1];
        if(indexPath.row == self.selectedIndex)
        {
            SelectedCell * tmpCell = (SelectedCell *)[tableView dequeueReusableCellWithIdentifier:@"Selected"];
            [tmpCell.label1 setText:[NSString stringWithFormat:@"%@", [innerData objectAtIndex:0]]];

            cell = tmpCell;
             tmpCell.textLabel.numberOfLines=2;

        }
        else
        {
            RegularCell * tmpCell = (RegularCell *)[tableView dequeueReusableCellWithIdentifier:@"Regular"];
            [tmpCell.label1 setText:[NSString stringWithFormat:@"%@", [innerData objectAtIndex:0]]];

            cell = tmpCell;
             tmpCell.textLabel.numberOfLines=2;
        }
    }
        break;
}



return cell;
}

}

现在,我想存储每个字段中输入的文本,该字段特定于该单元格。我搜索了很多教程,但找不到它

请尽快为我提供合适的解决方案


提前谢谢

你能告诉我这个的全部功能吗。。因此,我可以共享一个精确的代码我有一个带有动态单元格的表视图当我选择每个单元格时,子视图将作为手风琴出现在该视图中,我必须放置一个文本字段或文本视图,作为该行的注释框。每行都应有不同的注释。我必须将该值存储到用户默认值或sqlitedatabaseso u将在tableview的外侧有一个textfield或textview。一旦你选择了任何一行,你就会显示文本字段,一旦用户在其中输入信息/注释,它就会显示在该单元格中。。。这是正确的吗?不,当我点击一个单元格时,我的表中有很多项目。它应该展开一个注释框,我应该在其中输入对该项目的注释,我必须保存它。我想你说的和@Charan_Giri一样。1.点击单元格。2.显示UITextField以输入注释3。保存注释。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if(indexPath.row == 0)
    return;

if(indexPath.row != self.selectedIndex && self.selectedIndex > 0)
{
    // Selected different row while there is another selected row

    int oldIndex = self.selectedIndex;
    self.selectedIndex = indexPath.row;

    NSArray * innerData = [self.data objectAtIndex:oldIndex - 1];

    [self.data removeObjectAtIndex:oldIndex - 1];

    NSIndexPath * deselectedIndexPath = [NSIndexPath indexPathForRow:oldIndex inSection:0];
    [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:deselectedIndexPath] withRowAnimation:UITableViewRowAnimationNone];

    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.0 * NSEC_PER_SEC),
                   dispatch_get_main_queue(),
                   ^{
                       [self.data insertObject:innerData atIndex:deselectedIndexPath.row - 1];
                       [tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:deselectedIndexPath] withRowAnimation:UITableViewRowAnimationTop];
                       [tableView reloadData];

                       NSArray * innerData = [self.data objectAtIndex:indexPath.row - 1];
                       [self.data removeObjectAtIndex:indexPath.row - 1];
                       [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationNone];
                       dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.2 * NSEC_PER_SEC),
                                      dispatch_get_main_queue(),
                                      ^{
                                          [self.data insertObject:innerData atIndex:indexPath.row - 1];
                                          [tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationTop];
                                          [tableView reloadData];
                                      });
                   });
}
else
{
    if(indexPath.row == self.selectedIndex) // selected active row -> close
        self.selectedIndex = -1;
    else                                    // selected inactive row -> open
        self.selectedIndex = indexPath.row;

    NSArray * innerData = [self.data objectAtIndex:indexPath.row - 1];
    [self.data removeObjectAtIndex:indexPath.row - 1];
    [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationNone];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.2 * NSEC_PER_SEC),
                   dispatch_get_main_queue(),
                   ^{
                       [self.data insertObject:innerData atIndex:indexPath.row - 1];
                       [tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationTop];
                       [tableView reloadData];
                   });
}