1

正如我在标题中所写,我试图将在pickerview(由数组填充)上选择的值写到detailTextLabel我单击以调出pickerview 的单元格中。(pickerview 显示在 actionSheet 中)。

我试图做的是设置两个可变数组:pickerDatatableData. 最初,该pickerData数组包含pickerview 中显示的值,并且该tableData数组只有一个值。

当调用以下方法时,我试图将选择记录到tableData数组中,然后用这个值替换原来的值detailTextLabel

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
    [tableData replaceObjectAtIndex:row withObject:[pickerData objectAtIndex:row]];
}

由数组detailTextLabel填充tableData,这发生在方法中:

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

使用代码行:

cell.detailTextLabel.text = [pickerData objectAtIndex:indexPath.row];

我究竟做错了什么?关于我应该如何以不同的方式执行此操作的任何建议?我只编程了一个月,我确信这有一个简单的解决方案。先感谢您!

4

3 回答 3

0

您说您正在使用 tableData 来更新 detailTextLabel 但是当您查看- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 您正在使用cell.detailTextLabel.text = [pickerData objectAtIndex:indexPath.row];导致问题的 pickerData 时。您应该使用cell.detailTextLabel.text = [tableData objectAtIndex:indexPath.row];并希望它能解决您的问题。

于 2013-02-01T14:41:27.090 回答
0

您可以在您的中访问您的 detailTextLabel pickerView didSelectRow,然后将您的选择器值设置为此label

UILabel *detailTextLabel=(UILabel*)[[tableView cellForRowAtIndexPath:indexPath] detailTextLabel ];

detailTextLabel.text=[pickerData objectAtIndex:row];
于 2013-02-01T14:53:28.393 回答
0

您需要初始化 tableData NSMutableArray : self.tableData = [[[NSMutableArray alloc] init] autorelease];

 id)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
UITableViewCell *cell =[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:index inSection:0];
cell.detailTextLabel.text = [pickerData objectAtIndex:row];
    [self.tableData insertObject:[pickerData objectAtIndex:row] atIndex:index]
}
于 2013-02-01T15:14:38.873 回答