简体   繁体   English

numberOfRowsInSection的数组计数

[英]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.

相关问题 动态数组返回的数量numberOfRowsInSection - Dynamic array returning count in numberOfRowsInSection 如何从嵌套可解码模型中的数组中获取 numberOfRowsInSection 中的计数 - how to get count in numberOfRowsInSection from Array in nested Decodable Model 如何使用数组获取numberOfRowsInSection的计数 <Dictionary<String,Any> &gt;迅速? - How to get count for numberOfRowsInSection using Array<Dictionary<String,Any>> in swift? uitableview numberOfRowsInSection计数 - uitableview numberOfRowsInSection count 数组的numberOfRowsInSection等于0 - Array equals 0 in numberOfRowsInSection 尝试让numberOfRowsInSection计数等于Swift中另一个文件的数组计数 - Attempting to get numberOfRowsInSection count to be equal to an array count from another file in Swift iOS:在numberOfRowsInSection中返回2个计数值 - iOS: Return 2 count values in numberOfRowsInSection Swift 5:从tableView numberOfRowsInSection返回数组计数时索引超出范围 - Swift 5: index out of range when returning the array count from tableView numberOfRowsInSection iOS Swift:TableView numberOfRowsInSection返回错误的计数 - iOS Swift: TableView numberOfRowsInSection returning wrong count 根据字典数组为tableview设置numberOfRowsInSection - Set numberOfRowsInSection for tableview as per the Array of Dictionaries
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM