gpt4 book ai didi

ios - 如何将数据加载到 ios 中自定义 tableview 单元格内的选择器 View ,objective c

转载 作者:行者123 更新时间:2023-11-28 21:31:10 25 4
gpt4 key购买 nike

我有一个 TableView 和几个自定义单元格。在一个自定义单元格中有一个选择器 View 。我需要将数据加载到位于 cellForRowAtIndexPath 的选择器 View

这是我的cellForRowAtIndexPath 方法

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *cellIdentifierOne = @"detailCell";
FlightUserTableViewCell *detailcell = [tableView dequeueReusableCellWithIdentifier:cellIdentifierOne];

NSString *cellIdentifierTwo = @"detailCelltwo";
FlightUserSecondTableViewCell *detailcelltwo = [tableView dequeueReusableCellWithIdentifier:cellIdentifierTwo];

if (indexPath.section == 0) {

if (indexPath.row ==0) {

//detailcell.titlepickerView **here i want to load the data **

return detailcell;
}
return detailcelltwo;
}



return detailcelltwo;
}

我该怎么做。我知道如果我们正常加载数据到选择器 View ,我们必须实现它的委托(delegate)方法,如下所示。

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 1;
}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
return [cabinArray count];
}

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
return [cabinArray objectAtIndex:row];
}

那么我该如何为自定义单元格内的选择器 View 执行此操作。希望得到您的帮助。

作为答案,我已经像这样在 custome tableview 单元格中实现了 delegate 方法

- (void)awakeFromNib {
// Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];

// Configure the view for the selected state
}

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 1;
}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{

return [leadandadultTitle count];
}

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
return [leadandadultTitle objectAtIndex:row];
}

然后在 cellForRowAtIndexpath 中我已经这样实现了。

 if (indexPath.section == 0) {

NSString *cellIdentifierOne = @"detailCell";
FlightUserTableViewCell *detailcell = [tableView dequeueReusableCellWithIdentifier:cellIdentifierOne];

if (indexPath.row ==0) {

if([traveller isEqualToString:@"LEAD"])
{

detailcell.leadandadultTitle = leadandadultTitle;
detailcell.titlepickerView.delegate = self;
detailcell.titlepickerView.dataSource = self;
}
else
{
detailcell.leadandadultTitle = childandinfantTitle;
}



return detailcell;
}

注意:我尝试像上面那样设置 delegatedatasource,还尝试拖动 pickerview 并选择 delegatedatasource 但是

numberOfComponentsInPickerView:]: 无法识别的选择器发送到实例 这给出了

最佳答案

在您的自定义单元格中实现选择器委托(delegate)协议(protocol),并设置您希望选择器在 cellForRowAtIndexPath: 上显示的数据

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *cellIdentifierOne = @"detailCell";
FlightUserTableViewCell *detailcell = [tableView dequeueReusableCellWithIdentifier:cellIdentifierOne];

NSString *cellIdentifierTwo = @"detailCelltwo";
FlightUserSecondTableViewCell *detailcelltwo = [tableView dequeueReusableCellWithIdentifier:cellIdentifierTwo];

if (indexPath.section == 0) {
if (indexPath.row ==0) {
detailCell.cabinArray = cabinArray
return detailcell;
}
return detailcelltwo;
}

return detailcelltwo;
}

关于ios - 如何将数据加载到 ios 中自定义 tableview 单元格内的选择器 View ,objective c,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36058054/

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