gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 13:03:04 25 4
gpt4 key购买 nike

我正在开发我的第一个应用程序,我是 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com