【发布时间】:2017-08-17 04:13:28
【问题描述】:
我正在我的 CarPlay 音频应用程序中添加一个列表(表格视图)。在 AppDelegate.m 中,我有
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
..........
[MPPlayableContentManager sharedContentManager].dataSource = self;
[MPPlayableContentManager sharedContentManager].delegate = self;
return YES;
}
我还在 AppDelegate.m 中实现了 MPPlayableContentDataSource 方法:
- (NSInteger)numberOfChildItemsAtIndexPath:(NSIndexPath *)indexPath
{
switch (indexPath.row)
{
case 0:
return 3;
case 1:
return 2;
default:
return 4;
}
}
- (MPContentItem *)contentItemAtIndexPath:(NSIndexPath *)indexPath
{
MPContentItem *contentItem = [[MPContentItem alloc] initWithIdentifier:@"container"];
.................
return contentItem;
}
但是,应用程序在切换 (indexPath.row) 时崩溃并显示“与 UITableView 一起使用的索引路径无效。传递给表视图的索引路径必须恰好包含两个指定节和行的索引。如果可能,请使用 UITableView.h 中 NSIndexPath 上的类别。我在这里做错了吗?提前致谢。
【问题讨论】:
-
您是手动创建
indexPath吗? -
没有。我没有手动创建 indexPath。我使用数据源方法中的 indexPath -numberOfChildItemsAtIndexPath:.
-
你有一个 tableView 并且你正在使用这个 indexPath 吗?
-
没有。我还没有列表(tableView)。现在我想我看到了问题:因为我的 CarPlay 应用程序中还没有列表(tableView),所以数据源方法中的 indexPath 无效(长度为零且路径为空)。那么我应该如何在 CarPlay 应用程序中创建列表(tableView)?非常感谢。
标签: ios user-interface audio carplay