gpt4 book ai didi

ios - 在 PickerView 中设置行标题

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

我正在努力尝试在我的 PickerView 中设置我的 titleForRow。目前,我有一个访问用户播放列表数据的选择器。然后我想把它转移到选择器上。但是,由于 didSelectRow 方法,我知道选择器数据是正确的。我一直不走运,试图在 PickerView 中显示实际数据。

**我已经将我的代码编辑成现在的样子。目前,已购买在我的选择器 View 中一遍又一遍地重复。有办法解决吗?

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

MPMediaQuery *myPlaylistsQuery = [MPMediaQuery playlistsQuery];
NSArray *playlists = [myPlaylistsQuery collections];

return [playlists count];

}

-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
if (pickerView.tag == 1) {
lblRound.text = [_roundArray objectAtIndex:row];
}
else if (pickerView.tag == 2) {
lblTime.text = [_timeArray objectAtIndex:row];
}
else if (pickerView.tag ==3) {

MPMediaQuery *myPlaylistsQuery = [MPMediaQuery playlistsQuery];
NSArray *playlists = [myPlaylistsQuery collections];

for (MPMediaPlaylist *playlist in playlists) {
lblPlaylist.text = [playlist valueForProperty: MPMediaPlaylistPropertyName];
}
}

}

#pragma mark Picker Delegate Methods

- (NSString*)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {

NSString *title;

if (pickerView.tag == 1) // this is otherPickerview
{
title=[_roundArray objectAtIndex:row]; // your logic to get title for otherpickerview

}
else if (pickerView.tag == 2) // this is citysPickerview
{
title=[_timeArray objectAtIndex:row]; // your logic to get title for cityspickerview

}
else if (pickerView.tag == 3)
{
[self showPlaylistData];

MPMediaQuery *myPlaylistsQuery = [MPMediaQuery playlistsQuery];
NSArray *playlists = [myPlaylistsQuery collections];

for (MPMediaPlaylist *playlist in playlists)
title = [playlist valueForProperty: MPMediaPlaylistPropertyName];
}

return title;

}

最佳答案

问题是您未能将此类设置为选择器 View 的数据源,并且未能实现数据源方法。因此,没有数据。咨询documentation on UIPickerViewDataSource . (或者只看任何工作示例并以此为基础编写代码。)

关于ios - 在 PickerView 中设置行标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30881490/

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