按下添加按钮时添加另一个输入字段

时间:2015-01-05 05:22:25

标签: ios objective-c swift

我正在尝试创建一个应用程序,其中包含用户可以输入信息的字段。问题是我不知道会有多少个字段。例如,假设您有一个食谱应用程序,您可以在其中输入成分。有些食谱可能有2种成分,有些可能有更多成分。我想要的是如果需要比当前屏幕上的字段更多的字段,用户可以按下添加按钮并且它将根据需要创建附加字段而不是具有一些可能未使用的字段。我一直在四处寻找一个我正在寻找的例子而没有运气的例子。任何帮助将非常感激。

2 个答案:

答案 0 :(得分:0)

最好的方法是UITableView。在那里,您可以根据需要添加尽可能多的单元格。

There is a apples example虽然它不像你想要的那样但是你可以得到图片。

希望这会有所帮助.. :)

答案 1 :(得分:-1)

 Try this it will help you.. 

<pre><div id="divingredient" class="input_wrapar_search">
    <span>Ivingredient Type : </span>
    <input type="text"  maxlength="50"  id="txtIngredient0" />
</div> </pre>
<script>
    var counter = 0;
    $("[id$=btnaddnew]").live("click", function (e) {
        counter++;
        if (counter > 10) {
            alert("Can not add more than 10 price !");
            return false;
        }
        $("#divingredient").append('<input type="text"  maxlength="50"  id="txtIngredient' + counter + '" />');
        e.preventDefault();

    });
    $("[id$=btnremove]").live("click", function (e) {

        if (counter == 0) {
            alert("one price is manadatory !");
            return false;
        }
        $("#txtIngredient" + counter).remove();
        counter--;
        e.preventDefault();
    });
</script>
<asp:Button ID="btnaddnew" runat="server" Class="btn" Text="Add New" />
 <asp:Button ID="btnremove" runat="server" Class="btn" Text="Remove" /></pre>