如何以与iOS音乐应用程序相同的方式搜索iPod库?我想做一般查询,返回每个艺术家,专辑和歌曲的结果.例如,如果我搜索Kenny Chesney,我希望歌曲查询返回所有Kenny Chesney歌曲(以及包含Kenny Chesney的任何歌曲标题或专辑.)当我为每个属性(歌曲标题,专辑)创建此查询和谓词时标题,艺术家姓名),一个空数组返回.
这里有一些代码可以让您更好地了解我想要实现的目标:
MPMediaPropertyPredicate *songPredicate =
[MPMediaPropertyPredicate predicateWithValue:searchText
forProperty:MPMediaItemPropertyTitle
comparisonType:MPMediaPredicateComparisonContains];
MPMediaPropertyPredicate *albumPredicate =
[MPMediaPropertyPredicate predicateWithValue:searchText
forProperty:MPMediaItemPropertyAlbumTitle
comparisonType:MPMediaPredicateComparisonContains];
MPMediaPropertyPredicate *artistPredicate =
[MPMediaPropertyPredicate predicateWithValue:searchText
forProperty:MPMediaItemPropertyArtist
comparisonType:MPMediaPredicateComparisonContains];
MPMediaQuery *songsQuery = [MPMediaQuery songsQuery];
[songsQuery addFilterPredicate:songNamePredicate];
[songsQuery addFilterPredicate:artistNamePredicate];
[songsQuery addFilterPredicate:albumNamePredicate];
NSLog(@"%@", [songsQuery items]);
Run Code Online (Sandbox Code Playgroud)
我有这个工作通过分别运行每个谓词的查询,但这似乎非常低效!
我有一个以纵向模式呈现的UITabBarController.在其中一个选项卡上,我有一个按钮,以模态方式显示UIViewController(一个简单的故事板segue执行操作).
我希望这个模态视图以横向模式显示,但我不能让它自动转动.
我在模态视图控制器中有这个
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}
Run Code Online (Sandbox Code Playgroud)
我已将landscapeLeft添加到.plist支持的方向(虽然这也允许TabBar旋转,我不想要)
我还将它添加到模态视图的ViewDidLoad中
[UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationLandscapeLeft;
Run Code Online (Sandbox Code Playgroud)
但我不能让它自己旋转.
谢谢
编辑----
似乎应该是自动旋转甚至没有被调用!
此外,我正在尝试检测方向,下面的代码总是显示2,无论方向如何!
if ([[UIDevice currentDevice] orientation] == UIInterfaceOrientationPortrait) {
NSLog(@"1");
self.hostView.frame = CGRectMake(0, 60, 200, 255);
} else {
NSLog(@"2");
self.hostView.frame = CGRectMake(0, 45, 480, 255);
}
Run Code Online (Sandbox Code Playgroud)
编辑2 ---
我的错.我想我应该提到我正在使用iOS 6.显示器在iOS 5上自动旋转.不推荐使用shouldAutorotateToInterfaceOrientation,所以我需要阅读新方法.
xcode cocoa-touch uiinterfaceorientation modalviewcontroller ios
我正在尝试构建简单的XML数据库(在BaseX或eXist-db中),但我无法确定如何修改文档中的值:
内容很简单,因为测试:
<p>
<pl>
<id>6></id>
</pl>
</p>
Run Code Online (Sandbox Code Playgroud)
我正在尝试构建类似函数的东西,<pl>如果元素不存在则会插入元素,如果存在则替换它.但XQuery给了我麻烦:
当我尝试使用if-then-else逻辑时:
if (exists(/p/pl[id=6]/name)=false)
then insert node <name>thenname</name> into /p/pl[id=6]
else replace value of node /p/pl[id=6]/name with 'elsename'
Run Code Online (Sandbox Code Playgroud)
我收到错误Error: [XUDY0027] Replace target must not be empty.显然我很困惑,为什么在两种情况下评估else部分,因此错误.当我清空其他部分时:
if (exists(/p/pl[id=6]/name)=true)
then insert node <name>thenname</name> into /p/pl[id=6]
else <dummy/>
Run Code Online (Sandbox Code Playgroud)
然后我明白了Error: [XUST0001] If expression: no updating expression allowed.
当我尝试声明更新功能时,即使它报告错误:
declare namespace testa='test';
declare updating function testa:bid($a, $b)
{
if (exists(/p/pl[id=6]/name)=true)
then insert node <name>thenname</name> into /p/pl[id=6]
else <dummy/>
};
testa:bid(0,0)
Run Code Online (Sandbox Code Playgroud)
Error: …
ios ×2
basex ×1
cocoa-touch ×1
exist-db ×1
iphone ×1
mpmediaitem ×1
mpmediaquery ×1
objective-c ×1
xcode ×1
xquery ×1