Ios 当单元格不可见时,如何访问和迭代UITableView中的contentView.SubView?
我正在UITableView中创建一个表单,当我使用for(UIView*view in cell.contentView.subviews){}收集表中的所有数据时,即使它遍历UITableView中的每个单元格,它也看不到行中任何尚不可见的数据。如何访问此数据 我尝试添加ScrollToRowatineXpath,但徒劳地希望它能够加载可见的行,但没有效果Ios 当单元格不可见时,如何访问和迭代UITableView中的contentView.SubView?,ios,objective-c,uitableview,Ios,Objective C,Uitableview,我正在UITableView中创建一个表单,当我使用for(UIView*view in cell.contentView.subviews){}收集表中的所有数据时,即使它遍历UITableView中的每个单元格,它也看不到行中任何尚不可见的数据。如何访问此数据 我尝试添加ScrollToRowatineXpath,但徒劳地希望它能够加载可见的行,但没有效果 for (int i=0; i < countArray.count; i++) { //count needs to be f
for (int i=0; i < countArray.count; i++) { //count needs to be for the cells entire tableView
NSIndexPath *indexPath = [NSIndexPath indexPathForRow: i inSection: 0]; //create NSIndexPath for each cell in section 0
UITableViewCell *cell = [self.table cellForRowAtIndexPath:indexPath]; //iterating through each cell available in table
NSLog(@"iterationing through cell \"%i\"",indexPath.row);
[self.table scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];
NSLog(@"moving view to \"%i\"",indexPath.row);
for (UIView *view in cell.contentView.subviews){ //find views within cell.contentview
if ([view isKindOfClass:[UITextField class]]){ // narrow those views down to anything with class UITextField
UITextField* txtField = (UITextField *)view; // instantiate the UITextField
if (txtField.tag == 201) { //find the tag of the instantiated UITextField
if (dataSwitch == 0) { //we are collecting data
[tmpArray addObject:[NSString stringWithFormat:@"%@",txtField.text]];
}else if (dataSwitch == 1) { //we are distributing data
txtField.text = [tmpArray objectAtIndex:i];
}
}
else if (txtField.tag == 202) { //find the tag of the instantiated UITextField
if (dataSwitch == 0) { //we are collecting data
[tmpArray addObject:[NSString stringWithFormat:@"%@",txtField.text]];
}else if (dataSwitch == 1) { //we are distributing data
txtField.text = [tmpArray objectAtIndex:i];
}
}
else if (txtField.tag == 203) { //find the tag of the instantiated UITextField
if (dataSwitch == 0) { //we are collecting data
[tmpArray addObject:[NSString stringWithFormat:@"%@",txtField.text]];
}else if (dataSwitch == 1) { //we are distributing data
txtField.text = [tmpArray objectAtIndex:i];
}
}
else if (txtField.tag == 204) { //find the tag of the instantiated UITextField
if (dataSwitch == 0) { //we are collecting data
[tmpArray addObject:[NSString stringWithFormat:@"%@",txtField.text]];
}else if (dataSwitch == 1) { //we are distributing data
txtField.text = [tmpArray objectAtIndex:i];
}
}
else if (txtField.tag == 205) { //find the tag of the instantiated UITextField
if (dataSwitch == 0) { //we are collecting data
[tmpArray addObject:[NSString stringWithFormat:@"%@",txtField.text]];
}else if (dataSwitch == 1) { //we are distributing data
txtField.text = [tmpArray objectAtIndex:i];
}
}
else {
NSLog(@"Data is being lost %@ with tag %i",[tmpArray objectAtIndex:i], txtField.tag);
}
}
// End of isKindofClass
if ([view isKindOfClass:[UIImageView class]]){ // narrow those views down to anything with class UIImage
UIImageView* image = (UIImageView *)view; // instantiate the UIImage
if (dataSwitch == 0) { //we are collecting data
[tmpArray addObject:image];
NSLog(@"collecting image data and storing in %i",i);
}else if (dataSwitch == 1) { //we are distributing data
image = [tmpArray objectAtIndex:i];
}
}
if ([view isKindOfClass:[UILabel class]]){ // narrow those views down to anything with class UILabel
UILabel* label = (UILabel *)view; // instantiate the UILabel
if (label.tag == 301) { //find the tag of the instantiated UILabel
if (dataSwitch == 0) { //we are collecting data
[tmpLabelArray addObject:[NSString stringWithFormat:@"%@",label.text]];
NSLog(@"%@",[NSString stringWithFormat:@"%@",label.text]);
}
}
}
if ([view isKindOfClass:[UISegmentedControl class]]){ // narrow those views down to anything with class UISegmentedControl
UISegmentedControl* seg = (UISegmentedControl *)view; // instantiate the UISegmentedControl
if (dataSwitch == 0) { //we are collecting data
[tmpArray addObject:[NSString stringWithFormat:@"%i",seg.selectedSegmentIndex]];
}
}
} // End of Cell Sub View
}// Counter Loop
for(int i=0;i
在此方面的任何帮助都将不胜感激
谢谢你,尼克
**编辑**
这就是我最后做的
邓肯C是对的,像这样获取信息是不对的。可以设置tableview的动画,以将可重用的单元格带入视图并收集数据,但它看起来很混乱,这是一种更干净的方法
-(void)textFieldDidEndEditing:(UITextField *)textField {
if(textField.tag >= 0 && textField.tag <= 10) {
CGPoint location = [self.table convertPoint:textField.frame.origin fromView:textField.superview];
NSIndexPath *indexPath = [self.table indexPathForRowAtPoint:location]; //get the indexPath of the textField.
NSString *str1 = [NSString stringWithFormat:@"%i",stack];
NSString *str2 = [NSString stringWithFormat:@"%i",indexPath.row];
NSString *str3 = [NSString stringWithFormat:@"%@",textField.text];
NSMutableArray *cellAnswer = [[NSMutableArray alloc] initWithObjects:str1,str2,str3, nil];
}
}
-(void)textfieldDendediting:(UITextField*)textField{
如果(textField.tag>=0&&textField.tag您对表视图的工作原理以及您的