添加到UIButton的UITableView
问题描述:
在一个ViewController分别位于UITableView,UITextField和UIButton。我需要通过按钮将UITextField的文本添加到表格的单元格中。我设置压制过程中的标志:添加到UIButton的UITableView
- (IBAction)addingButon:(id)sender {
_addingFlag = true;
}
然后在表的方法做到以下几点:
- (UITableViewCell *)tableView:(UITableView*)tableViewcellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellID = @"dataCell";
UITableViewCell *cell = [tableViewdequeueReusableCellWithIdentifier:cellID];
while (true) {
if (_addingFlag && _textBox.text.length != 0) {
cell.textLabel.text = _textBox.text;
[tableView reloadData];
}
_addingFlag = false;
break;
return cell;
}
数据表滚动,只有当并出现在陌生的顺序。你能告诉我如何解决它。使用Objective-C只需几天。
答
tableView:cellForRowAtIndexPath:
应该立即返回。请拨打电话[tableView reloadData]
addingButton:
:
- (IBAction)addingButon:(id)sender {
[self.tableView reloadData];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellID = @"dataCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
cell.textLabel.text = _textBox.text;
return cell;
}
谢谢!它正在工作!但我需要通过文本字段在其他单元格中推送新文本,并同时将旧文本保存在先前的单元格中。我怎样才能做到这一点? – deMasta
您应该使用'NSArray'属性,并使用它来存储旧值。 –
已经完成,但无论如何感谢您的答案! :) – deMasta