标签: nsnotificationcenter

XCODE - iOS内存泄漏让我疯狂我觉得它是NSNotificationCenter,但希望新鲜的眼睛可以看到我不能

这里的代码是从RootViewController启动的模态视图,用于在电影下方显示带缩略图幻灯片的视频,然后显示绑定到电影的定时指令.

这一切都有效,但有一个内存泄漏/缺乏发布,我看不出去寻找并花了三天时间试图解决它,现在是时候寻求帮助了......

如果我通过注释来禁用NSNotificationCenter(在.m中突出显示)我没有任何关于内存的问题并保留定时文本.但我也没有任何缩略图.我试过插入[[NSNotificationCenter alloc] removeObserver:self]; 在众多的地方,看看是否会为我摆脱它.但是,唉,无济于事.

我也试过发布'backgroundTimer'但是当我尝试编译和运行时它并没有给我留下太深刻的印象.

本质上,我第一次加载模态视图,没有任何问题,一切似乎都很好 - 但是,如果我用 - (IBAction)关闭它:(id)sender; 似乎有些事情没有发布,因为下次我启动相同的页面时内存使用量增加了大约30%(大致是缩略图生成使用的量),并且每次重新启动时增加的量大致相同模态视图.

请记住,我是一个新手,这个错误可能是一个血腥的愚蠢的你知道的人.但是为了完成这个项目,我很乐意接受你想要的任何虐待.

另外,这是我明天的生日,如果我可以对它进行排序,那将是(相当可悲)最好的礼物!

这是代码........

.H

#import <UIKit/UIKit.h>
#import <MediaPlayer/MPMoviePlayerController.h>
#import "ImageViewWithTime.h"
#import "CommentView.h"

@interface SirloinVideoViewController_iPad : UIViewController {
    UIView *landscapeView;
    UIView *viewForMovie;
    MPMoviePlayerController *player;
    UILabel *onScreenDisplayLabel;
    UIScrollView *myScrollView;
    NSMutableArray *keyframeTimes;
    NSArray *shoutOutTexts;
    NSArray *shoutOutTimes;
    NSTimer *backgroundTimer;
    UIView *instructions;
}

-(IBAction)close:(id)sender;
-(IBAction)textInstructions:(id)sender;

@property (nonatomic, retain) IBOutlet UIView *instructions;
@property (nonatomic, retain) NSTimer *theTimer;
@property (nonatomic, retain) NSTimer *backgroundTimer;
@property (nonatomic, retain) IBOutlet UIView *viewForMovie;
@property (nonatomic, retain) MPMoviePlayerController *player; …
Run Code Online (Sandbox Code Playgroud)

video modal-dialog nstimer nsnotificationcenter ios

0
推荐指数
1
解决办法
2528
查看次数

Mac侦听事件:复制到粘贴板

我正在阅读NSPasteboard,然后想找到....

  1. 我试图找到正确的通知方法,该方法监听数据到剪贴板的复制事件.

  2. 此外,我试图找到复制到剪贴板的数据的文件路径.哪个是粘贴板对象.

  3. 如果我从浏览器中的页面复制文本,我试图找出如何获取文本从中复制的页面的URL地址.

有任何想法吗?

macos events copy nsnotificationcenter nspasteboard

0
推荐指数
1
解决办法
1864
查看次数

NSNotificationCenter - 具有不同名称的相同观察者

是否可以在NSNotificationCenter中使用不同名称链接一个方法?

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(Finish:) name:@"FinishDownload_data1" object:nil];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(Finish:) name:@"FinishDownload_data2" object:nil];
Run Code Online (Sandbox Code Playgroud)

......等

在我的代码中,当我调用通知时,我在userInfo Dictionary中传递其名称和其他一些参数.

我想要这个的原因是因为我有运行时生成的事件.它们具有相同的主体,但仅在保存目标方面有所不同,具体取决于_data#.我希望每个下载都在同一个地方处理.

问题是,如果我使用它,则不会调用通知.

objective-c nsnotificationcenter ios

0
推荐指数
1
解决办法
582
查看次数

当控制中心打开时,为什么快速应用程序在后台运行?

在我的快速应用程序中,当活动将转到后台时,我正在注销,但是当控制中心打开时,它将在后台运行.我的代码如下:

class MyApp:UIViewController{
   NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(appMovedToBackground), name: UIApplicationWillResignActiveNotification, object: nil)

   func appMovedToBackground() {
        print("App moved to background!")
        self.logout() 
    }
}
Run Code Online (Sandbox Code Playgroud)

有什么方法可以在活动在后台运行时注销,但在控制中心打开时不会注销.

nsnotificationcenter ios swift

0
推荐指数
1
解决办法
708
查看次数

NSNotification失败....为什么?

我正在努力让NSNotifications发挥作用.此刻,没有成功.

在我的appDelegate.m文件中,我有:

[[NSNotificationCenter defaultCenter] postNotificationName:@"first" object:nil];
Run Code Online (Sandbox Code Playgroud)

在我的mainViewController.m中,在viewDidLoad方法中我有

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(firstRun)name:@"first" object:nil];
Run Code Online (Sandbox Code Playgroud)

并创建了一个方法(在mainViewController.m中也是如此):

-(void) firstRun:(NSNotification *) notification
{
        NSLog(@"This works!");
}
Run Code Online (Sandbox Code Playgroud)

但是,在运行应用程序时,我在日志中看不到任何输出.

我的代码出了什么问题?请指教.

objective-c nsnotificationcenter ios

-1
推荐指数
1
解决办法
236
查看次数

本地NSNotification消防日期需要在12小时后设置

如何在12小时后准确设置我的localNotifications防火日期属性?我的代码片段如下,

 UILocalNotification *localNotif = [[UILocalNotification alloc] init];
 if (localNotif == nil)
     return;
 localNotif.fireDate = [NSDate date]; // how to set after 12 hours
 localNotif.timeZone = [NSTimeZone defaultTimeZone];
Run Code Online (Sandbox Code Playgroud)

任何建议表示赞赏.

objective-c nsdate nsnotificationcenter ios

-1
推荐指数
1
解决办法
639
查看次数

NSNotification发送多个对象?

我正在学习如何使用NSNotificationCenter.我的理解是,对于每个通知,您可以发送单个对象.有没有办法发送包含多个对象的通知,还是我必须为每个对象发布新通知?

nsnotificationcenter ios

-1
推荐指数
1
解决办法
2591
查看次数