gpt4 book ai didi

ios - 添加 UITextField 作为 UITableViewCell 的 subview 在 IOS 6 中工作正常但在 IOS 7 中它不工作?

转载 作者:行者123 更新时间:2023-11-28 22:17:00 25 4
gpt4 key购买 nike

在我的应用程序中,我有一个登录表单,用户可以在其中输入一个字段密码。所以我在 cellForRowAtIndexPath 的函数调用期间在 UITableViewCell 中添加了 UITextField 的 subview 。

UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"loginViewCell"];

UITextField *editableTextField = nil;

// Done Some settings of editableTextField

// Adding Subview

[cell addSubview:editableTextField];

当用户按下登录按钮时,我调用了一个选择器函数名称登录

UITableViewCell *cell = [loginTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];

//然后我遍历 cellsubviews 并从 UITextField subview 中提取用户输入的密码。

for (UIView *view in cell.subviews) {

if ([view isKindOfClass:[UITextField class]]) {
usernameField = (UITextField *)view;
break;
}
}

这在 IOS 7 之前工作正常

在网上搜索后,我发现在 IOS 7 中苹果更改了 UITableViewCell 的 View 层次结构,现在插入了额外的类 UITableViewCellScrollView.

我在我的选择器函数登录中调试我的代码,它正在获取我添加 subview 的相同单元格 我打印 cell.subview 的名称正在显示 UITableViewCellScrollView 之前显示的是 UITableViewCellcontentView(ios7 之前)

如何从 UITableViewCellsubeview 中提取密码?

最佳答案

cellForRowAtIndexPath:方法不是添加 subview 的正确位置,而是操作它们的正确位置。你真的应该创建一个 UITableViewCell 的子类有一个@property UITextField它被添加到 initWithStyle:reuseIdentifier: 中的单元格中方法。

[self.contentView addSubview:self.passwordField];

然后您可以访问这个特定的 UITextField[cell passwordField]或者随便你怎么调用它。

关于ios - 添加 UITextField 作为 UITableViewCell 的 subview 在 IOS 6 中工作正常但在 IOS 7 中它不工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21407847/

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