ios - 如何将文本字段中的数据保存到表格 View 中?

标签 ios objective-c iphone tableview textfield

我正在开发我的第一个应用程序,我是 Objective-C 的新手,我想做的是当有人在 text field 中键入然后按下按钮时它会保存它到 table view。有谁知道如何做到这一点或知道任何教程。

最佳答案

您所要做的就是每次按下按钮时刷新/更新您的表格 View 。

- (IBAction)buttonPressed:(id)sender {
NSString *textNameToAdd = yourTextField.text;
[containerArrayForTableView addObject:textNameToAdd];
[myTableView reloadData];
}

// UITABLEVIEW DELEGATES
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return 1;
 }

 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
// Return the number of rows in the section.
// Usually the number of items in your array (the one that holds your list)
return [containerArrayForTableView count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
//Where we configure the cell in each row

static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell;

cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// Configure the cell... setting the text of our cell's label
cell.textLabel.text = [containerArrayForTableView objectAtIndex:indexPath.row];
return cell;
}

引用here如果您在配置 UITableView 时遇到问题。

关于ios - 如何将文本字段中的数据保存到表格 View 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19330931/

相关文章:

ios - 我如何管理可能无休止地将 View Controller 推送到导航 Controller 堆栈? iOS

ios - 我的应用程序推送通知仅在我客户的 iPhone 中不起作用

iphone - 开放式GL-ES 2.0 : Touch detection

objective-c - Xcode 使用正则表达式查找多行

objective-c - 多个@protocols 的奇怪或错误警告

ios - 使用 AFNetworking 进行图像缓存

iphone - 传递参数使指针来自整数而不进行强制转换

iphone - Xcode 单元测试

ios - Swift:UITextField Delegate 从未设置,或者方法从未被调用

ios - iPhone App在模拟器上运行速度变慢