我添加了一个观察者
override func viewDidLoad()
{
super.viewDidLoad()
NSNotificationCenter.defaultCenter().addObserver(self, selector:"selector name", name: "observer name", object:nil)
...
}
Run Code Online (Sandbox Code Playgroud)
在deinit中移除观察者时,
deinit
{
NSNotificationCenter.defaultCenter().removeObserver(self, forKeyPath: <some string>)
}
Run Code Online (Sandbox Code Playgroud)
该应用程序有时会崩溃:
由于未捕获的异常'NSRangeException'而终止应用程序,原因是:'无法从NSNotificationCenter中删除关键路径"some string"的观察者"class",因为它未注册为观察者.
所以我想添加do/catch
deinit
{
do{
try NSNotificationCenter.defaultCenter().removeObserver(self, forKeyPath: <some string>)
}catch{}
}
Run Code Online (Sandbox Code Playgroud)
但我得到一个警告:
catch块无法访问,因为do块中没有抛出任何错误
应用程序崩溃了
当我添加一个尝试
deinit
{
do{
try NSNotificationCenter.defaultCenter().removeObserver(self, forKeyPath: <some string>)
}catch{}
}
Run Code Online (Sandbox Code Playgroud)
我收到这个警告:
在try expresion中没有调用抛出函数
应用程序崩溃了
应该怎么做?
我正在Use of undeclared identifier使用我使用的每个Facebook对象
遵循本教程: 教程:如何在FACEBOOK SDK 4.1.X for SWIFT中分享
但我有以下错误:
我通过cocoapods添加了Facebook框架:
pod 'FBSDKCoreKit'
pod 'FBSDKShareKit'
Run Code Online (Sandbox Code Playgroud)
它已成功安装
我添加了桥接头
#ifndef Bridging_Header_h
#define Bridging_Header_h
#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import <FBSDKShareKit/FBSDKShareKit.h>
#endif /* Bridging_Header_h */
Run Code Online (Sandbox Code Playgroud)
桥接头连接:
我已经配置了我的.plist
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>fb*****</string>
</array>
</dict>
</array>
<key>FacebookAppID</key>
<string>*****</string>
<key>FacebookDisplayName</key>
<string>*****</string>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>facebook.com</key>
<dict>
<key>NSIncludesSubdomains</key> <true/>
<key>NSThirdPartyExceptionRequiresForwardSecrecy</key> <false/>
</dict>
<key>fbcdn.net</key>
<dict>
<key>NSIncludesSubdomains</key> <true/>
<key>NSThirdPartyExceptionRequiresForwardSecrecy</key> <false/>
</dict>
<key>akamaihd.net</key>
<dict>
<key>NSIncludesSubdomains</key> <true/>
<key>NSThirdPartyExceptionRequiresForwardSecrecy</key> <false/>
</dict>
</dict>
</dict>
Run Code Online (Sandbox Code Playgroud)
这是代码:
let content : FBSDKShareLinkContent = …Run Code Online (Sandbox Code Playgroud) 为了初始化具有xib的视图,我使用了initWithCoderfunction.但是,如果我需要使用自定义参数初始化xib,该怎么办呢?
我需要这样的东西:
- (id)initWithCoder:(NSCoder *)aDecoder
andTitle:(NSString *)titleString
{
self = [super initWithCoder:aDecoder];
if (self) {
self.titleLabel = titleString;
}
return self;
}
Run Code Online (Sandbox Code Playgroud)
我什么时候打电话给它?之后awakeFromNib?
我是JW的新手,似乎无法实现最简单的球员.请帮帮我.
我创建了一个html并将其放入我的项目中.与jwplayer.flash.swf,jwplayer.html5.js,jwplayer.js在同一个地方
我的html文件看起来像这样(Home.html):
<html>
<head>
<title>Title of the document</title>
<script type="text/javascript" src="jwplayer.js"></script>
<script type="text/javascript">jwplayer.key="myKey"</script>
</head>
<body>
<div id='player_8955'></div>
<script type='text/javascript'>
jwplayer('player_8955').setup({
file: "http://www.youtube.com/watch?v=ac7KhViaVqc",
width: "480",
height: "270",
image: "http://content.bitsontherun.com/thumbs/3XnJSIm4-640.jpg",
});
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
在控制器类中:
- (void)viewDidLoad
{
[super viewDidLoad];
htmlPlayerWebView=[[UIWebView alloc]initWithFrame:CGRectMake(20, 51, 674,381)];
[self.view addSubview:htmlPlayerWebView];
}
-(void)loadVideo
{
NSString *path = [[NSBundle mainBundle] pathForResource:@"Home" ofType:@"html"];
NSString *HTMLString = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
[htmlPlayerWebView loadHTMLString:HTMLString baseURL:[NSURL URLWithString:path]];
}
Run Code Online (Sandbox Code Playgroud)
这些函数被调用.但没有任何反应.
我根据手册安装了.
但只有当我将消息发送到所有iOS平台时,才会收到推送通知.但是当我将按摩发送到特定版本或特定设备进行测试时,设备上不会收到按摩.
可能是什么问题呢?
奇怪的是,当我使用新版本运行应用程序时,我没有在版本下拉列表中看到这个版本几天.即使代码确实达到了
FIRApp.configure()
Run Code Online (Sandbox Code Playgroud)
iphone push-notification ios firebase firebase-notifications
我已经设置了一个全局tintColor,我可以在界面构建器中看到它,当我选择UITabBar以及UITabBarController时,仍然在我运行应用程序时,所选UITabBarItem的色调是iOS默认(蓝色),而不是我的已经设定.我错过了什么?
PS UITabBarController被推送到navigationController,它不是rootViewController
A ViewController有个UICollectionView。其中一个单元格包含JWVideoView。该应用经常prepareForReuse在该单元中崩溃。
日志中没有有价值的信息。因此,我在弄清坠机原因时遇到了麻烦。
我创建了一个演示崩溃的项目示例。您可以找到它https://github.com/fuxlud/JWExample
如果删除了cell和之间的链接videoView,则不会发生崩溃。
import UIKit
class VideoArticleElementCollectionViewCell: UICollectionViewCell {
// MARK: - Properties
public var imageURL: String? { didSet { videoView?.imageURL = imageURL } }
public var videoId: String? { didSet { videoView?.videoId = videoId } }
@IBOutlet private var videoView: JWVideoView?
// MARK: - Reuse
override func prepareForReuse() {
super.prepareForReuse() // Crashing here! (Thread 1: EXC_BAD_ACCESS (code=1, address=0x7e8))
videoView?.stopPlayingVideo()
}
deinit {
videoView?.stopPlayingVideo()
}
} …Run Code Online (Sandbox Code Playgroud) 我想找出项目中实际使用的图像.当我试图找到以编程方式设置的图像名称时,我可以在搜索时在相关的类中看到它们.对于在xib中设置的图像,情况并非如此.是否有一些解决方法来查找图像是否在某些xib中使用?

我想呈现一个带有2个按钮的UIAlertController.
一个按钮应该关闭警报,第二个按钮应该执行操作但在屏幕上保持警报.是否有一些可以执行的配置,它不会关闭警报?
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"title"
message:@"message"
preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:@"Do Something"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action) {
//Pressing this button, should not remove alert from screen
}]];
[alert addAction:[UIAlertAction actionWithTitle:@"Close"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action) {
//Regular functionality- pressing removes alert from screen
}]];
[alert show];
Run Code Online (Sandbox Code Playgroud)
建议将此(防止UIAlertController解除)作为可能的答案,但问题涉及文本字段.我需要其中一个操作按钮,以便在按下时不关闭警报.
我为按钮ID预定了枚举:
typedef enum
{
button1ID = 407,
button2ID = 999,
button3ID = 408,
button4ID = 409,
} TOP_MENU_BUTTON_TYPE;
Run Code Online (Sandbox Code Playgroud)
我需要找出我收到的ID是否在enum中被诽谤.我怎样才能做到这一点?就像是:
if(id in TOP_MENU_BUTTON_TYPE)
Run Code Online (Sandbox Code Playgroud)