我在我的设置页面中有一个UISwitchcontroller来改变主页面中的图像,所以我把从吃网页到主页面的通知..但只有一个通知我每次活跃,,我的设置页面切换代码看这样NSnotifiaction疑惑
-(IBAction)_clickswitchlowlight:(id)sender
{
if(switchControll.on){
[switchControll setOn:YES animated:YES];
[[NSNotificationCenter defaultCenter] postNotificationName:NOTIF_lowlighton object:nil];
}
else{
[switchControll setOn:NO animated:YES];
[[NSNotificationCenter defaultCenter] postNotificationName:NOTIF_lowlightoff object:nil];
}
}
在我的主要page.h..i
编写代码
extern NSString * const NOTIF_lowlighton;
extern NSString * const NOTIF_lowlightoff;
中的.m主要页面的执行上面我写这篇文章
NSString * const NOTIF_lowlighton = @"lowlighton";
NSString * const NOTIF_lowlightoff = @"lowlightoff";
在viewWillAppear中我写这篇文章的代码
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(clicklowlighton:) name:@"lowlighton" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(clicklowlightoff:) name:@"lowlightoff" object:nil];
}
那么这段代码改变图像
- (void)clicklowlighton:(NSNotification *)notif
{
[[self multiPageView] setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"bgipad"]]];
}
- (void)clicklowlightoff:(NSNotification *)notif
{
[[self multiPageView] setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"[email protected]"]]];
}
我只得到clicklowlightoff通知,我没有拿到第一通知......在任何缺失我的代码? 预先感谢。
你为什么改变开关的状态呢? [switchControll setOn:YES animated:YES]; ?? – 2012-04-27 10:53:29
@Ubersoldat检查它是否打开..是一个错误? – stackiphone 2012-04-27 10:58:15
不,我的意思是,当它已经处于“开”状态时,试图将其设置为“开”。为什么? – 2012-04-27 11:05:27