gpt4 book ai didi

iphone - 在 UITableViewCell 中访问 UITextField

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

我正在使用一个 UITableView 和一个带有 UITextField 的子类原型(prototype)单元格。该单元在 4 个部分中总共使用了 4 次。这是它的代码:

...
- (void)viewDidLoad
{
[super viewDidLoad];
cellTitles = [[NSArray alloc] initWithObjects:@"Smell", @"Taste", @"Suits", @"Notes", nil];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [cellTitles count];
}

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

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return [cellTitles objectAtIndex:section];
}

- (AddInfoCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"AddInfoCell";

AddInfoCell *addInfoCell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

if (addInfoCell == nil) {
addInfoCell = [[AddInfoCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
addInfoCell.cellTextView.delegate = self;

return addInfoCell;
}

我想将每个单元格中的文本添加到 dataSource 对象:

-(IBAction)nextButtonPressed:(id)sender {
...
[[dataSource objectAtIndex:dataSourceIndex] setObject:* forKey:@"Smellnote"];
[[dataSource objectAtIndex:dataSourceIndex] setObject:** forKey:@"Tastenote"];
//etc

}

*单元格 1 中的文本

**单元格 2 中的文本

如何访问我想要的文本?

最佳答案

也许你看错了。为什么不让 textField 的委托(delegate)成为单元格本身,即在 Cell 的类中,在 init... 方法中将委托(delegate)设置为 File'sOwner 或 self。

创建对数据源的引用并将数据源连同字典的@"Key"一起传递给您的单元格。

cell.dataSource = self.dictionary;
cell.dataKey = @"Tastenote";
//in cell .m
//textFieldDelegate method...
[self.dataSource setObject:self.cellTextView.text forKey:self.dataKey];

关于iphone - 在 UITableViewCell 中访问 UITextField,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12698170/

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