Ios 如何获取';是从数组填充的吗?
我有一个带有5个不同单元格的tableviewcell。每个视图都有一个标签,其中包含以下内容之一。1个文本字段、1个文本、1个视图、1个开关或1个滑块。我试图在索引路径中查找行的tableviewcell,以便检索用户输入的信息。下面是我对电池和不同开关的代码。如果可能的话,我只需要知道如何做到这一点。谢谢(p.s.)我在考虑只标记元素,而不是为行查找单元格,所以您将看到标记代码Ios 如何获取';是从数组填充的吗?,ios,arrays,multidimensional-array,nsindexpath,tableviewcell,Ios,Arrays,Multidimensional Array,Nsindexpath,Tableviewcell,我有一个带有5个不同单元格的tableviewcell。每个视图都有一个标签,其中包含以下内容之一。1个文本字段、1个文本、1个视图、1个开关或1个滑块。我试图在索引路径中查找行的tableviewcell,以便检索用户输入的信息。下面是我对电池和不同开关的代码。如果可能的话,我只需要知道如何做到这一点。谢谢(p.s.)我在考虑只标记元素,而不是为行查找单元格,所以您将看到标记代码 -(UITableViewCell *)listCell:(UITableView *)tableView Ind
-(UITableViewCell *)listCell:(UITableView *)tableView IndexPath:(NSIndexPath*)indexPath
{
static NSString *textFieldIdentifier = @"textFieldCell";
static NSString *textViewIdentifier = @"textViewCell";
static NSString *switchIdentifier = @"switchCell";
static NSString *seekBarIdentifier = @"seekBarCell";
static NSString *datePickerIdentifier = @"datePickerCell";
//DBSectionDetailsTableViewCell *cell = (DBSectionDetailsTableViewCell *) [tableView dequeueReusableCellWithIdentifier:textViewIdentifier];
UITableViewCell *cell6 = [tableView dequeueReusableCellWithIdentifier:datePickerIdentifier];
results = [listArray objectAtIndex:[indexPath row]];
if([indexPath row] < listArray.count)
{
if (([[results objectAtIndex:2]isEqualToString:@"EditText"]))
{
DBSectionDetailsTableViewCell *cell2 = [tableView dequeueReusableCellWithIdentifier:textFieldIdentifier forIndexPath:indexPath];
cell2.titleLabel.text = [results objectAtIndex:1];
//title button
cell2.textField.tag = [indexPath row];
cell2.textField.delegate = self;
[cell2.textField addTarget:self action:@selector(textFieldDidEndEditing:) forControlEvents:UIControlEventTouchUpInside];
return cell2;
}
else if (([[results objectAtIndex:2]isEqualToString:@"EditTextLarge"]))
{
TextViewTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:textViewIdentifier forIndexPath:indexPath];
// cell = textFieldCell;
cell.titleLabel.text = [results objectAtIndex:1];
cell.textView.tag = [indexPath row];
cell.textView.delegate = self;
// [cell.textView addTarget:self action:@selector(textViewDidEndEditing:) forControlEvents:UIControlEventTouchUpInside];
return cell;
}
else if (([[results objectAtIndex:2]isEqualToString:@"Switch"]))
{
SwitchTableViewCell *cell3 = [tableView dequeueReusableCellWithIdentifier:switchIdentifier forIndexPath:indexPath];
// cell3 = switchCell;
cell3.titleLabel.text = [results objectAtIndex:1];
cell3.switchOutlet.tag = [indexPath row];
return cell3;
}
else if (([[results objectAtIndex:2]isEqualToString:@"SeekBar"]))
{
SeekBarTableViewCell *cell4 = [tableView dequeueReusableCellWithIdentifier:seekBarIdentifier forIndexPath:indexPath];
//cell4 = seekBarCell;
cell4.titleLabel.text = [results objectAtIndex:1];
cell4.slider.tag = [indexPath row];
return cell4;
}
else if (([[results objectAtIndex:2]isEqualToString:@"DatePicker"]))
{
DatePickerTableViewCell *cell5 = [tableView dequeueReusableCellWithIdentifier:datePickerIdentifier forIndexPath:indexPath];
//cell5 = datePickerCell;
cell5.titleLabel.text = [results objectAtIndex:1];
cell5.datePicker.tag = [indexPath row];
cell5.datePicker.delegate = self;
[cell5.datePicker addTarget:self action:@selector(datePickerDidEndEditing:) forControlEvents:UIControlEventTouchUpInside];
return cell5;
}
}
//UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
return cell6;
-(UITableViewCell*)列表单元格:(UITableView*)表视图索引XPath:(NSIndexPath*)索引XPath
{
静态NSString*textFieldIdentifier=@“textFieldCell”;
静态NSString*textViewIdentifier=@“textViewCell”;
静态NSString*switchIdentifier=@“switchCell”;
静态NSString*seekBarIdentifier=@“seekBarCell”;
静态NSString*datePickerIdentifier=@“datePickerCell”;
//DBSectionDetailsTableViewCell*单元格=(DBSectionDetailsTableViewCell*)[tableView dequeueReusableCellWithIdentifier:textViewIdentifier];
UITableViewCell*cell6=[tableView dequeueReusableCellWithIdentifier:datePickerIdentifier];
结果=[listArray objectAtIndex:[indexPath行]];
if([indexPath行]
}您可以使用
[tableView cellForRowAtIndexPath:indexPath]
从表中获取可见单元格。屏幕外的单元格将从UITableView
中删除,您将无法访问它们,因为它们将被放回可重用单元格队列
注意1:您不应该依赖
UITableView
来存储当前数据状态。它会丢弃屏幕外滚动的单元格,所以如果您不将数据保存在其他位置,数据将永远丢失
注2:此代码并不特别安全:
results = [listArray objectAtIndex:[indexPath row]];
if([indexPath row] < listArray.count) // This is always true.
// If it isn't true, the above
// objectAtIndex: will crash your app.
results=[listArray objectAtIndex:[indexPath行]];
if([indepath row]
您应该在用户为每个单元格输入信息时保存信息,因为一旦单元格离开视图,您就无法访问该单元格,以便以后重新使用。此外,tableview当然是动态的,因为tableviewcells是由消费者在后端设置的内容填充的。非常混乱。如果您有该单元格并想知道索引路径,请使用indexPathForCell
。但听起来您有一个数组索引,并希望将其与索引路径相关联——这是您的数据源对象的责任。。。我试图使用类似于nsindepath*newIndex=[nsindepath indexPathForRow:0第0节:0];DBSECTIONDETAILSTABLEVEWCELL*cell2=(DBSECTIONDETAILSTABLEVEWCELL*)[listTable cellForRowAtIndexPath:newIndex];在我的“save”函数中,但我仍然返回“null/nil”。我认为对按钮进行标记可能更好,我只是想看看是否可以使用NSIndex实现我想要的功能,而无需执行所有标记和附加函数调用等。UITableViewcellForRow..
返回“表示表中某个单元格的对象,如果该单元格不可见或indexPath超出范围,则返回nil。”当前未显示的单元格不存在。谢谢,它将一直存在