0

我正在开发一个 iPhone 应用程序,在一个视图中,我已经将UITextViewUITableView. ViewController我需要做的是,在文本视图中输入数据后,用户将点击下方的按钮。单击按钮后,在 textview 中输入的数据应该会加载到 tableview 中。但它不是这样工作的。

在这里,我所做的是,我在按钮操作中编写了以下代码,

[self.tableView reloadData];

非常感谢任何建议

4

2 回答 2

3

确保您NSMutableArray使用新值更新 ,您用于在UITableView.

在点击按钮时,

[arrValues addObject:txtBox.text];
[self.tableView reloadData];
于 2012-10-09T06:57:48.140 回答
1

This method handle your rowCount of TableView

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [arrayData count];
}

And this method will make your cell and showing cell data.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

So you will have to add textField.text in that array which you're using for numberOfRowsInSection: and cellForRowAtIndexPath:

-(void)buttonClick:(id)sender
 {
     [arrayData addObject:textField.text];
     [self.tableView reloadData];
 }

And make sure textField.text should not be empty other wise data will not be visible. After calling [self.tableView reloadData] method all tableView delegates method will be call again and arrayData will increase the numberOfRows for your tableView.

EDIT: As you're saying in comment that you're navigating the view so each time your viewDidLoad: will be call and your array will have the same object which your initialize in viewDidLoad: if you want that your array remain same objects then dont initialize it static, use plist or Database and save your array data in Database in viewDidDisappear: method and refresh your array in viewWillAppear: method before adding your tableView.

于 2012-10-09T07:10:36.563 回答