gpt4 book ai didi

ios - 单击uitextfield时调用uitableview-数据不显示-iOS

转载 作者:行者123 更新时间:2023-11-29 12:45:43 24 4
gpt4 key购买 nike

我想在点击特定的 uitextfield 时在 uitableview 中显示数据。我没有在 taleview 中获取数据。请检查以下内容并帮助我。

   - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"CellIdentifier";



UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier ];
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] ;



cell.accessoryType = UITableViewCellAccessoryCheckmark;
[cell.textLabel setFont:[UIFont fontWithName:@"Bold" size:20]];


if (ethnicityField.tag == 1)
{
cell.textLabel.text = [data objectAtIndex:indexPath.row];

}

if (languageField.tag == 2)
{
cell.textLabel.text = [langData objectAtIndex:indexPath.row];



}

在这里,当我点击第一个 textfield 时,它显示空表并崩溃。它没有采用确切的标签值。请帮忙。

- (NSInteger)tableView:(UITableView *)aTableView numberOfRowsInSection:(NSInteger)section{
int row = 0;
if (ethnicityField.tag == 1)
{
row = [data count];
}
if (languageField.tag == 2)
{
row = [langData count];
}
return row;
}

崩溃报告:
实际上我有 2 个数组,一个有 5 个值,另一个有 11 个值,问题是 textfield 都采用第一个数组,如果我在第二个 textfield 中选择第 5 个对象,它显示以下错误。

*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 9 beyond bounds [0 .. 4]'

最佳答案

我相信 ethnicityField 和 languageField 总是有相同的标签,所以 numberOfRowsInSection 总是返回 [data count];

您可以做的是在显示表格时检查文本字段是否处于事件状态。

- (NSInteger)tableView:(UITableView *)aTableView numberOfRowsInSection:(NSInteger)section{
int row = 0;
if ([ethnicityField isFirstResponder])
{
row = [data count];
}
else if ([languageField isFirstResponder])
{
row = [langData count];
}
return row;
}

关于ios - 单击uitextfield时调用uitableview-数据不显示-iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23734449/

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