1

我无法更改值或更改声明的任何变量或对象。任何人都可以看到有什么问题吗?

在我的应用委托方法中。

- (void)applicationDidEnterBackground:(UIApplication *)application
{

    MainPage *mp = [[MainPage alloc]init];

    mp.newTime = [[NSDate date] timeIntervalSinceDate:mp.date];
    [mp.timer invalidate];
    mp.switchT = 1;
    mp.playBarButton.enabled = YES;
    mp.pauseBarButton.enabled = NO;
    mp.stopBarButton.enabled = YES;
   [mp.avPlayer pause];

}

以上这些操作均未执行。在我的mainpage.h文件中,我声明如下:

@property (nonatomic, retain) AVAudioPlayer *avPlayer;
@property (strong, retain) NSTimer *timer;
@property (strong, retain) NSDate *date;
@property (nonatomic) NSTimeInterval newTime;
@property (nonatomic) NSInteger switchT;
@property (strong, nonatomic) IBOutlet UIBarButtonItem *playBarButton;
@property (strong, nonatomic) IBOutlet UIBarButtonItem *pauseBarButton;
@property (strong, nonatomic) IBOutlet UIBarButtonItem *stopBarButton;

当然,在我的实现文件中,这些都是综合的,并且mainpage.m在我的 appDelegate 文件中没有与我的代码一起工作。任何人都可以看到问题吗?请注意,这是一个功能齐全的应用程序,一切正常,只是无法在我的 applicationDidEnterBackground 方法中执行以下代码,我假设这是我的属性的制作方式?我在应用程序委托中编写的代码也没有错误。

4

2 回答 2

2

这将MainPage *mp = [[MainPage alloc]init];创建一个 MainPage对象。更改一个对象中的值不会影响另一个MainPage对象的显示。

要么给你的应用程序委托一个你实际显示的对象的引用,要么在里面放置一个后台通知的处理程序,MainPage以便它可以完成自己的工作。

于 2013-09-17T19:31:02.833 回答
2
NSNotificationCenter defaultCenter] addObserver:self selector:@selector(goBackground) name:UIApplicationDidEnterBackgroundNotification object:nil]; // and later
 - (void) goBackground { [timer invalidate], timer = nil; }
于 2013-11-06T20:33:38.750 回答