如何设置MPMoviePlayerViewController的通知?它与MPMoviePlayerController中的相同吗?
请显示示例
objective-c mpmovieplayercontroller nsnotificationcenter ios
我的应用程序中有一个"设置"标签,询问用户是否要"在应用关闭时收到通知?"
通常,用户必须在常规选项卡的IOS5通知中心执行此操作.我可以为自己的应用修改这些设置吗?
我正在尝试调试我最近转换为使用ARC的项目.我很难确定为什么对象没有被释放并留在内存中(是否有一种简单的方法可以查看哪个引用将对象保存在内存中?)
通知中心链接似乎存在一个问题.在viewDidLoad上我注册了三个通知:
[notificationCenter addObserverForName: kAudioPlaybackStart
object: nil
queue:[NSOperationQueue mainQueue]
usingBlock:^(NSNotification *note) {
[self handle_PlaybackStateStart:nil];
}];
[notificationCenter addObserverForName: kAudioPlaybackStop
object: nil
queue:[NSOperationQueue mainQueue]
usingBlock:^(NSNotification *note) {
[self handle_PlaybackStateStop:nil];
}];
[notificationCenter addObserverForName: kAudioPlaybackPause
object: nil
queue:[NSOperationQueue mainQueue]
usingBlock:^(NSNotification *note) {
[self handle_PlaybackStatePause:nil];
}];
Run Code Online (Sandbox Code Playgroud)
然后,当viewController完成后,我调用一个函数unLoad:
- (void) unLoad {
[[NSNotificationCenter defaultCenter] removeObserver:self];
_mediaPlayerHelper = nil;
_article = nil;
_tableView = nil;
}
Run Code Online (Sandbox Code Playgroud)
我有一个单独的函数的原因是除非释放所有对象,否则不会调用viewDidUnload,所以我需要一些东西来释放它们.目前我在viewDidDisappear上调用它们.
但是,在注释掉观察者时,代码工作正常(并且查看卸载),但是观察者看起来它似乎不起作用并且视图保留在内存中.有什么建议?
iphone objective-c nsnotificationcenter ios automatic-ref-counting
我有一个UITabBarController,其中有4个标签。这些标签中的每个标签都是单独的UIViewController。我在这4个VC的每一个上都有一个对象,这些对象使用NSNotification来按某个对象时执行操作。4个VC都以相同的方式响应通知,因为它是每个页面上的相似对象。当按下此对象时,它将在当前视图控制器上显示一个视图。问题是,如果我现在移至其他3个选项卡中的任何一个,则该视图也位于其VC上。这是因为当在任何VC上按下通知时,所有4个选项卡上的通知都会得到响应。我需要它仅响应用户当前使用的VC,而不响应选项卡栏中的其他任何用户。
有没有办法使它正常工作?也许是一个阈值,您可以设置通知在被调用后可以执行其选择器的次数?这样,我可以将其设置为1,并且在任何给定时间(如果该通知被称为选择器)只能被调用1次。
我正在使用的对象实现类型要求我使用NSNotification,因此无法更改交互方式。
编辑:
此viewDidLoad方法位于我的选项卡栏中4个VC的顶级VC上。它们全部4个都直接使用它或从中继承。
- (void) viewDidLoad
{
...
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didSelectItemFromCollectionView:) name:@"didSelectItemFromCollectionView" object:nil];
}
Run Code Online (Sandbox Code Playgroud)
动作处理程序:
- (void) didSelectItemFromCollectionView:(NSNotification *)notification
{
NSDictionary *cellData = [notification object];
if (cellData)
{
NewVC *pushToVC = [self.storyboard instantiateViewControllerWithIdentifier:@"PushToVC"];
[self.navigationController pushViewController:pushToVC animated:YES];
}
}
Run Code Online (Sandbox Code Playgroud)
4个VC中的每一个都是a,UITableViewController并且具有带有可按下对象的单元格。此NSNotificationCenter操作使操作得以执行。
使用一个时我将使用的内存/处理是什么:
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(dismissKeyboard) name:UIKeyboardWillHideNotification object:nil];
Run Code Online (Sandbox Code Playgroud)
或者:
NSNotificationCenter * notificationCenter =
[notificationCenter addObserver:self selector:@selector(dismissKeyboard) name:UIKeyboardWillHideNotification object:nil];
Run Code Online (Sandbox Code Playgroud)
PS:我想到用NSNotificationCenter三个不同的东西。所以我的好奇心
KVO和NSNotificationCenter都可以处理价值变化.他们之间有什么区别?它们的正确用法是什么?
如何在Xamarin iOS中做到这一点?
下面的链接在AppDelegate中提到了Xamarin的OnActivated方法,但是我如何订阅ViewController,以便它知道该应用何时来自后台?
https://forums.xamarin.com/discussion/10594/where-is-applicationdidbecomeactive-in-xamarin-ios
我有一个视图,当键盘出现时调整约束.所以当键盘出现并消失时我会收到通知.
键盘已经显示并旋转屏幕时会出现上述行为.然后发生下一个动作:
因此,updateView函数接收第一个高度,然后接收不同的高度.这导致视图的奇怪移动调整值的两倍.
override func viewDidLoad() {
super.viewDidLoad()
// Creates notification when keyboard appears and disappears
NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardWillShow:"), name: UIKeyboardWillShowNotification, object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardWillHide:"), name: UIKeyboardWillHideNotification, object: nil)
}
deinit {
NSNotificationCenter.defaultCenter().removeObserver(self, name: UIKeyboardWillShowNotification, object: nil)
NSNotificationCenter.defaultCenter().removeObserver(self, name: UIKeyboardWillHideNotification, object: nil)
}
func keyboardWillShow(notification: NSNotification) {
self.adjustingHeight(true, notification: notification)
}
func keyboardWillHide(notification: NSNotification) {
self.adjustingHeight(false, notification: notification)
}
private func adjustingHeight(show: Bool, notification: NSNotification) {
// Gets notification information in an dictionary
var userInfo = …Run Code Online (Sandbox Code Playgroud) 如何NSNotification延迟发布.
我想到的一个解决方案: - 在performSelectorAfterDelay方法中发布通知.对此有没有更好的解决方案.
被NSNotificationQueue可以帮助我实现这一目标?
我的项目中有以下代码:
func viewDidLoad() {
super.viewDidLoad()
NotificationCenter.default.addObserver(
self,
selector: #selector(self.didUpdateHistory),
name: NSNotification.Name.init("didUpdateHistory"),
object: nil)
}
func didUpdateHistory() {
// Update some UI elements
}
Run Code Online (Sandbox Code Playgroud)
现在我的问题是:如果我发布一些班级通知我的项目,并且触发不是由UI元素造成的,我还需要包装代码与didUpdateHistory FUNC DispatchQueue.main.async { ... }或者我应该换行后调用本身?
另外,在何处添加观察者以及从何处发布通知是否重要?