English 中文(简体)
NStimer失事
原标题:NSTimer crashes

我正在寻找答案,我没有任何工作。

我有一位国家安全日记官,作为上诉人的属性,这个国家安全日记官应随时开枪,即使其行动是在背景(它是一个地方化标志,因此可以永远运作)的情况下。

This is the code:

if(conectar){
            self.myTimer = [[NSTimer scheduledTimerWithTimeInterval:10.0
                                                            target:self
                                                          selector:@selector(abrirPresencia)
                                                          userInfo:nil
                                                           repeats:NO]retain];
        iii
        else{
            self.myTimer = [[NSTimer scheduledTimerWithTimeInterval:10.0
                                                    target:self
                                                  selector:@selector(cerrarPresencia)
                                                  userInfo:nil
                                                           repeats:NO]retain];
        iii

After 10 seconds the app crashes, I have breakpoints in both methods and it doesnt stop, as if the method wasnt even called, instead of firing the method it crashes.

Here are the methods:

-(void)cerrarPresencia{
NSLog(@"SOY EL TIMERRRRR!!!! %@");
//[[UIApplication sharedApplication] applicationState] == UIApplicationStateBackground
if (YES){
    [self.location stopUpdatingLocation];
    [self disconnect];

iii
else{
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Ups!"
                                                        message:@"Según tu perfil querrías estar desconectado pero como lo estás usando hemos incluido este horario. Para cambiarlo sólo tienes que ir a editar perfil."
                                                       delegate:self 
                                              cancelButtonTitle:@"Ok" 
                                              otherButtonTitles:nil];
    [alertView show];

    [alertView release];
iii

iii

-(void)abrirPresencia{
NSLog(@"SOY EL TIMERRRRR!!!! %@");
if (YES){
    [self.location stopUpdatingLocation];
    [self disconnect];

iii
else{
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Ups!"
                                                        message:@"Según tu perfil querrías estar desconectado pero como lo estás usando hemos incluido este horario. Para cambiarlo sólo tienes que ir a editar perfil."
                                                       delegate:self 
                                              cancelButtonTitle:@"Ok" 
                                              otherButtonTitles:nil];
    [alertView show];

    [alertView release];
iii

iii

财产是:

@property (nonatomic, retain)NSTimer *myTimer;

任何想法?

最佳回答
NSLog(@"SOY EL TIMERRRRR!!!! %@");

提醒各位注意这一行文。

警告:转换率高于数据论据的百分比 [-Wformat,7]

?

注意这些警告。 页: 1 如果你不通过这些进一步的论点,其职能仍然处于它期望提出的论点的位置,可以发现,并造成坠毁。

问题回答

选择人错了,其形式必须是:

-(ave) abrir Presencia:NStimer*>thetimer

Also the selector needs to specify an argument with a trailing colon: selector:@selector(abrirPresencia)

摘自Amp/59/ docs:

+ (NSTimer *)scheduledTimerWithTimeInterval:(NSTimeInterval)seconds target:(id)target selector:(SEL)aSelector userInfo:(id)userInfo repeats:(BOOL)repeats

发出信号,在时间大火时瞄准目标。 选择人必须签名如下:

- (void)timerFireMethod:(NSTimer*)theTimer




相关问题
Asynchronous request to the server from background thread

I ve got the problem when I tried to do asynchronous requests to server from background thread. I ve never got results of those requests. Simple example which shows the problem: @protocol ...

objective-c: Calling a void function from another controller

i have a void, like -(void) doSomething in a specific controller. i can call it in this controller via [self doSomething], but i don t know how to call this void from another .m file. I want to call ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

NSUndoManager and runModalForWindow:

I have a simple Core Data app which displays a list of entities in the main window. To create or add new entities, I use a second modal window with a separate managed object context so changes can be ...

NSMutableArray values becoming "invalid"

I m trying to show a database information in a tableview and then the detailed information in a view my problem is as follow: I created a NSMutableArray: NSMutableArray *myArray = [[NSMutableArray ...

iPhone numberpad with decimal point

I am writing an iPhone application which requires the user to enter several values that may contain a decimal point (currency values, percentages etc.). The number of decimal places in the values ...

热门标签