菜鸟教程小白 发表于 2022-12-12 15:41:28

ios - 如何从所有文本字段中获取所有值


                                            <p><p>在谷歌搜索这个问题后,我设法做到了这一点</p>

<pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
    NSString *cellIdentifier = @&#34;InsertMarksCell&#34;;
    SaveAllExamMarksForAllStudentsTableViewCell *myCell = ;

    StudentPersonalInfo *newStudentName = feedItemsNow;

    myCell.txtStudentMark.text = @&#34;hello&#34;;
    myCell.txtStudentMark.delegate = self;
    myCell.txtStudentMark.tag = indexPath.row;

    return myCell;
}
</code></pre>

<p>此代码我设置文本字段“txtStudentMark”委托(delegate)并设置它的标签...</p>

<pre><code>-(void) textFieldDidEndEditing: (UITextField * ) textField
{
    NSString *text = [(UITextField *) text];
    NSLog(@&#34;%@&#34;,text);
}
</code></pre>

<p>我使用 NSLog 函数不断得到空值</p>

<p>我在自定义单元格中有一个文本字段,用户将填充数据,我需要从所有文本字段中获取所有数据,我走对了吗? </p>

<p>据我了解,我需要为 textField 设置标签并将其设置为委托(delegate),然后我可以通过标签调用 textfield 以获取其中的文本。</p>

<p>我怎样才能完成这项工作?</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>你为什么不使用</p>

<pre><code>-(void) textFieldDidEndEditing: (UITextField * ) textField
{
    NSString *text = ;
    NSLog(@&#34;%@&#34;,text);
}
</code></pre>

<p>? </p>

<p>您的问题是您将文本字段添加到单元格中,但要求查看此标签。</p>

<p>编辑:</p>

<p>从 tableview 获取您的文本字段</p>

<pre><code>-(void) textFieldDidEndEditing: (UITextField * ) textField
{
    UITableViewCell *cell = ];

    NSString *text = [(UITextField *) text];
    NSLog(@&#34;%@&#34;,text);
}
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 如何从所有文本字段中获取所有值,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/31142736/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/31142736/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 如何从所有文本字段中获取所有值