[英]Array count for numberOfRowsInSection
I'm grabbing music albums from the phone's music library. 我正在从手机的音乐库中获取音乐专辑。 I want to put the albums in sections (with the album cover as the section header image) and then the albums songs will fill in each sections table.
我想将专辑放在章节中(专辑封面作为章节标题图像),然后专辑歌曲将填充到每个章节表中。
I know how to get an array of albums, which will be used for numberOfSectionsInTableView
. 我知道如何获取相册数组,这些数组将用于
numberOfSectionsInTableView
。
But I'm not sure how the array of album tracks works for numberOfRowsInSection
. 但是我不确定
numberOfRowsInSection
的专辑曲目数组如何工作 。 Because I essentially need to navigate into the array of albums and then navigate inside of each album, which is two levels deep. 因为我本质上需要导航到相册阵列,然后在每个相册的内部导航,这是两个级别的深度。
Can anyone help me with this? 谁能帮我这个?
**AlbumsTableViewController.h**
- (void)viewDidLoad {
[super viewDidLoad];
Albums *albumsFromClass = [[Albums alloc] init];
albumsArrayForTVC = [albumsFromClass getAlbumsArray];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return albumsArrayForTVC.count;
}
**Albums.h**
- (NSArray *)getAlbumsArray {
_albumsMPMediaQuery = [MPMediaQuery albumsQuery];
_albumsArray = [_albumsMPMediaQuery collections];
return _albumsArray;
}
Print the array of albums, or the first object in the array, to see how the data is structured. 打印相册数组或数组中的第一个对象,以查看数据的结构。 Assuming it is nested arrays, albumsArrayForTVC[0] should grab an array of songs for a specific album.
假设它是嵌套数组,则albumsArrayForTVC [0]应该获取特定专辑的歌曲数组。 You can save this as a variable or do something like albumsArrayForTVC[0][2] to grab the third song in the first album.
您可以将其另存为变量,或执行诸如albumsArrayForTVC [0] [2]之类的操作来获取第一张专辑中的第三首歌曲。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.