【发布时间】:2019-04-09 13:22:13
【问题描述】:
我想填充 UICollectionView 的单元格。 我创建了一个自定义单元格,其中包含一个 Label 和 TextFiled,其 inputView 我以编程方式更改为 UIPickerView,因此它的行为类似于 pickerview,我的问题是我有自定义单元格 .h 和 .m 文件,并且我有一个 Controller 类,collectionview 是工作正常,但我无法将数据添加到 UIPickerview,因为它位于单独的 .h 文件中,因此它的 pickerview 委托和数据源方法将位于它的 .m 文件中。
但我的数据在主 VC 类中,我如何从 VC 填充选择器视图?
我是目标 c 的新手,如果没有清楚地解释我的问题,我很抱歉
我已经尝试在我的 VC 类中获取单元格并在 VC 类中填充单元格的选取器视图,但这不起作用,因为我无法在外部访问单元格的字段 - (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{} 方法。
- (NSInteger)numberOfComponentsInPickerView:(nonnull UIPickerView *)pickerView {
return 1;
}
- (NSInteger)pickerView:(nonnull UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
if(pickerView.tag==0){
return outboundBaggages.count;
}
return 0;
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
if(pickerView.tag==0){
NSString *key = [NSString stringWithFormat:@"%ld",(long)row];
ssrDescription = listOfOutboundSSR[key];
//cell.ssrTextField.text = listOfOutboundSSR[key];
//above line should be the right but it is field of cell and i
//can not access it outside of collectionview's method
}
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
if(pickerView.tag==0){
NSString *key = [NSString stringWithFormat:@"%ld",(long)row];
return listOfOutboundSSR[key];
}
return nil;
}
【问题讨论】:
标签: ios objective-c uicollectionview mobile-application