如何通过按下iPhone中的按钮动态地将行/单元格添加到UITableView [英] How to add row/cells dynamically to an UITableView by pressing a button in iPhone

查看:98
本文介绍了如何通过按下iPhone中的按钮动态地将行/单元格添加到UITableView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最初我有一个只有一个添加按钮的表格视图。

Initially i have a table view with only one add button.

当用户按下此按钮时,我需要增加单元格数量并添加单元格如下

when user press this button i need to increment the cells count and add the cells as follows

如何通过点击添加按钮来编写行数以及如何添加新行

How to write row count and how to add new rows by click on the add button

//行计数

 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{
    return **????** ;
}

//单元格/行上的内容

// Content on cells/rows

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
       ??????
}

// ###添加新行.. ###

// ### Add New Row.. ###

-(IBAction)myAction:(id)sender
{
    ???????? ;
}

提前致谢...

推荐答案

在你的应用程序中当你在btn中执行动作时,你必须向Array添加值。

In your application You have to add values to Array when you performing action in btn.

例如你的tableview是在cell.textLABEL.text中显示NSString。这些字符串在NSMutableArray中。

For example in your tableview you are displaying NSString in cell.textLABEL.text. These strings are in NSMutableArray.

现在调用buttonAction时

Now when buttonAction is called

in
myAction

{
    NSString *newString =@"NEW CELL";

    [tableArray addObject:newString];
    [tableView reloadData];
}

在你的应用程序中尝试这个关于你的模态的逻辑。

Try this logic in your application regarding to your modal.

我希望这个逻辑对你有所帮助。

I hope this logic will be helpful to you.

这篇关于如何通过按下iPhone中的按钮动态地将行/单元格添加到UITableView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆