gpt4 book ai didi

ios - 使用选择器动态更改 UICollectionCell 的标签

转载 作者:行者123 更新时间:2023-11-29 04:09:57 25 4
gpt4 key购买 nike

基本上我有一个带有 UICollectionView 和 UIPickerView 的类设置。正如我现在所拥有的,当用户单击单元格内的按钮时,选择器会弹出。我想做的是,当用户从选择器中选择某些内容时,文本字段的值会发生变化。以下是我的设置方法,但当我更改选择器中的值时什么也没有出现:

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
static NSString *CellIdentifier=@"cell";
activityCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
UITextView *nameLabel = (UITextView *)[cell viewWithTag:1];


nameLabel.text = [NSString stringWithFormat:@"%@ %@",[arrayHour objectAtIndex:[pickerView selectedRowInComponent:0]], [arrayMinute objectAtIndex:[pickerView selectedRowInComponent:1]]];

最佳答案

在您提供的代码中,您只需设置一次文本,而不是维护文本的实时链接。您需要跟踪选择器 View 是从哪个单元格呈现的(例如,使用 ivar),并在委托(delegate)方法 -[UIPickerViewDelegate pickerView:didSelectRow:inComponent:] 中设置文本再次查看标签。

关于ios - 使用选择器动态更改 UICollectionCell 的标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14569038/

25 4 0