我正在尝试在我的应用程序中播放音乐.音乐工作正常,但在切换viewControllers并返回主菜单后,我的音乐再次播放!这意味着几个相同的声音一起播放!我怎么解决这个问题?这是我的代码:
- (void)viewDidLoad {
NSString *music = [[NSBundle mainBundle] pathForResource:@"1music" ofType:@"mp3"];
myMusic = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:music] error:NULL];
myMusic.delegate = self;
myMusic.numberOfLoops = -1;
[myMusic play];
}
- (IBAction) scoreView {
ScoreViewController *scoreView = [[ScoreViewController alloc] initWithNibName:@"ScoreViewController" bundle:nil];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.view cache:YES];
[self.view addSubview: scoreView.view];
[UIView commitAnimations];
}
Run Code Online (Sandbox Code Playgroud)
编辑代码:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
NSString * musicSonati = [[NSBundle mainBundle] pathForResource:@"music" ofType:@"mp3"];
myMusic = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL …Run Code Online (Sandbox Code Playgroud) 我有一个自定义键盘,每当我第一次触摸退格键时,我的应用程序崩溃了!我怎么解决这个问题?
我的代码:
myText.text = [myText.text substringToIndex:([myText.text length]-1)];
Run Code Online (Sandbox Code Playgroud) 我的UITableView通过PopOverViewController打开,所以如何在app加载后自动加载其中一个单元格,
MainViewController上的单元格选择过程
- (void)setDetailItem:(id)newDetailItem {
if (detailItem != newDetailItem) {
[detailItem release];
detailItem = [newDetailItem retain];
//---update the view---
label.text = [detailItem description];
}
}
Run Code Online (Sandbox Code Playgroud)
和TableViewController中的单元格选择:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
myAppDelegate *appDelegate =
[[UIApplication sharedApplication] delegate];
appDelegate.viewController.detailItem = [list objectAtIndex:indexPath.row];
}
Run Code Online (Sandbox Code Playgroud)
我在TableViewController中使用此代码但不起作用!这意味着按下popOver按钮后代码只需突出显示单元格!
[myTableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:NO scrollPosition:0];
Run Code Online (Sandbox Code Playgroud)
我在上面不同的方法,如代码中使用viewDidAppear,viewWillAppear并且didSelectRowAtIndexPath和...
谢谢
我正在尝试使用Xcode 4构建一个通用应用程序.但是,它似乎与过去的版本有点不同.
我的项目使用基于视图的应用程序模板.我的问题是我添加了一个UIViewController子类,它有一个用于iPad的nib文件.如何为iPhone创建另一个具有相同类的nib文件?另外,如何确保为正确的平台加载正确的nib文件?
编辑:这是我的代码:
- (IBAction)BookView {
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
BookViewController *viewController = [[BookViewController alloc] initWithNibName:@"BookViewController" bundle:nil];
[self presentModalViewController:viewController animated:YES];
} else {
BookViewController *viewController = [[BookViewController alloc] initWithNibName:@"BookViewController_iPad" bundle:nil];
[self presentModalViewController:viewController animated:YES];
}
}
Run Code Online (Sandbox Code Playgroud) 我试图检测到设备上安装了Instagram的,以前我用这个代码来检测一个应用程序,但它似乎并不与iOS 6或非JB设备的工作:
NSString *filePath = @"/Applications/Instagram.app";
if ([[NSFileManager defaultManager] fileExistsAtPath:filePath])
{
[self checkingInstalledApp];
}
else
{
NSLog(@"no instagram installed");
}
Run Code Online (Sandbox Code Playgroud)
我查看这个问题,但他的回答给了我很多错误!任何解决方案
我在视图中有一些内容(例如图像,标签),最后一项是描述(UITextView).现在我试图根据UITextView文本动态滚动内容.这是我的代码:
- (void)viewDidAppear:(BOOL)animated {
_descriptions.scrollEnabled = NO;
[_descriptions sizeToFit];
_infoScrollView.contentSize = CGSizeMake(_contentsOnInfoView.frame.size.width,
_contentsOnInfoView.frame.size.height + _descriptions.frame.size.height);
}
Run Code Online (Sandbox Code Playgroud)
结果如下:
如你所见,有很多空的空间.我需要滚动到文本的末尾.
我启用了文档类型以将文件从其他应用程序导入或复制到我的应用程序.我有一些问题 :
1-在哪里创建从Inbox到Document目录移动文件的方法?这是对的地方吗?
func applicationWillEnterForeground(_ application: UIApplication)
2-在第一个视图控制器上我从Document目录中获取文件:
func getFileListByDate() -> [String]? {
let directory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
if let urlArray = try? FileManager.default.contentsOfDirectory(at: directory,
includingPropertiesForKeys: [.contentModificationDateKey],
options:.skipsHiddenFiles) {
return urlArray.map { url in
(url.lastPathComponent, (try? url.resourceValues(forKeys: [.contentModificationDateKey]))?.contentModificationDate ?? Date.distantPast)
}
.sorted(by: { $0.1 > $1.1 }) // sort descending modification dates
.map { $0.0 } // extract file names
} else {
return nil
}
}
Run Code Online (Sandbox Code Playgroud)
但是当文件导入我的应用程序时Inbox,我的表视图中有文件夹(项目),如何自动将文件从目录移动Inbox到Document目录并删除收件箱文件夹?
我有一个显示 UIImaveView 的 alpha 值的标签,我需要声明一个显示 0 到 100% 的百分比值。这是我的代码:
- (IBAction)changeAlpha:(id)sender {
_view3D.alpha = _slider.value;
_lableP.text = [NSString stringWithFormat:@"%f",_slider.value *100];
}
Run Code Online (Sandbox Code Playgroud)
但结果:
2014-03-04 16:50:35.676 App[3743:70b] 91.176468
2014-03-04 16:50:35.753 App[3743:70b] 90.000000
2014-03-04 16:50:35.782 App[3743:70b] 88.235298
Run Code Online (Sandbox Code Playgroud)
这不是一个数字仍然是一个浮点数,我如何显示这样的数字:
91% 90% 20%
谢谢 。
我正在尝试在今天的小部件扩展中读取核心数据属性.我在这里搜索了很多网站和问题,但我找不到解决方案!到目前为止,我已将应用组添加到我的应用中,然后更改此行App Delegate:
lazy var applicationDocumentsDirectory: NSURL = {
// file. This code uses a directory named "compony.AppName" in the application's documents Application Support directory.
let urls = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)
return urls[urls.count-1]
}()
Run Code Online (Sandbox Code Playgroud)
至 :
lazy var applicationDocumentsDirectory: NSURL? = {
return NSFileManager.defaultManager().containerURLForSecurityApplicationGroupIdentifier("group.com.myDomain.appgroupID") ?? nil
}()
Run Code Online (Sandbox Code Playgroud)
那么下一步又是什么呢?如何从小部件中心访问上下文实体等?如果有人帮助我,我将不胜感激.
我只有一个entity有几个attributes.
编辑
我创建了一个CoreDataStack.swift并将所有核心数据文件复制AppDelegate到新文件中.
将我的数据模型添加到小部件扩展:
在扩展中,viewDidLoad我厌倦了从模型中检索数据,但是当我运行小部件时没有任何反应:
context = CoreDataStack.defaultStack.managedObjectContext
do {
request = NSFetchRequest(entityName: "Event")
results = try context.executeFetchRequest(request)
print(results.count)
if results.count …Run Code Online (Sandbox Code Playgroud)我从互联网上下载了一个mp3文件,然后将其保存到文档目录,现在我尝试播放它,但是文件有一些像Space和的字符[],这使得应用程序崩溃,因为它找不到文件.原始文件名是这样的:
Artist - Track [320].mp3
Run Code Online (Sandbox Code Playgroud)
所以URL是:http://sample.com/Artist%20-%20Track%20[320].mp3
但是我的文件下载器url字符串用这个替换了那个标准的url:
http://sample.com/Artist%20-%20Track%20%5D320%5D.mp3
Run Code Online (Sandbox Code Playgroud)
正如你所看到的,[]人物已被替换为%5D!获取url字符串的正确方法是什么?
从UIWebView获取URL:
func requestIsDownloadable( request: URLRequest) -> Bool
{
let requestString : NSString = (request.url?.absoluteString)! as NSString
let fileExtention : String = requestString.pathExtension.lowercased()
fileTypes.fileTypeIcons(path: fileExtention as NSString , icon: fileType)
fileName.text = requestString.lastPathComponent as String
//******************************//
fileURL.text = request.url?.absoluteString
//******************************//
let isDownloadable : Bool = (
fileExtentions.contains(fileExtention)
)
return isDownloadable
}
func webView(_ webView: UIWebView, shouldStartLoadWith request: URLRequest, navigationType: UIWebViewNavigationType) -> Bool
{ …Run Code Online (Sandbox Code Playgroud) ios ×8
iphone ×8
xcode ×4
ipad ×3
objective-c ×3
swift ×3
core-data ×1
ios5 ×1
sdk ×1
uiscrollview ×1
uitableview ×1
uitextview ×1
url ×1