作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我用一个 textField 创建了一个简单的 UITableViewCell 。我给了它 1000 标签,这样我就可以从我的 cellForRowAtIndexPath 访问它,我还用一些数据预加载了数组,比如
- (void)viewDidLoad {
[super viewDidLoad];
_data = [[NSMutableArray alloc] init];
[_data addObject:@"Hassan"];
[_data addObject:@"Malik"];
[_data addObject:@""];
[_data addObject:@"dsldjsd"];
[_data addObject:@""];
[_data addObject:@"Halsda"];
[_data addObject:@"Hjdaslk"];[_data addObject:@"Hdjskldj"];
[_data addObject:@""];
[_data addObject:@"dsalkdmsalkn"];
[_data addObject:@""];
[_data addObject:@"jdopecnl"];
[_data addObject:@"Hassan"];
[_data addObject:@"sdsdklsmlfmf"];
[_data addObject:@""];
[_data addObject:@""];[_data addObject:@"sdnsad"];
[_data addObject:@"nsadn"];
[_data addObject:@"dlsadn"];
[_data addObject:@"sdslakdn"];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
NSLog(@"%ld",(long)indexPath.row);
NSLog(@"%@",[_data objectAtIndex:indexPath.row]);
UITextField * field = (UITextField*)[cell viewWithTag:1000];
if([[_data objectAtIndex:indexPath.row] length]>0)
{
[field setText:[_data objectAtIndex:indexPath.row]];
}
return cell;
}
最佳答案
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
NSLog(@"%ld",(long)indexPath.row);
NSLog(@"%@",[_data objectAtIndex:indexPath.row]);
UITextField * field = (UITextField*)[cell viewWithTag:1000];
field.text = @"";
if([[_data objectAtIndex:indexPath.row] length]>0)
{
[field setText:[_data objectAtIndex:indexPath.row]];
}
return cell;
}
关于ios - UiTextField 在 UtableView 中使用时会造成数据困惑。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36809465/
我是一个使用 Python 和 PyGTK 的 Linux 软件项目的开发人员。我们正在编写的程序依赖于许多第三方包,这些包可通过所有 mayor 发行版存储库获得。其中之一是 python 绑定(b
我是一名优秀的程序员,十分优秀!