我無法從我的NSData類訪問我的標籤,滑塊和開關,它們都位於UIViewController中。從NSObject類更改UISwitch的狀態
這是到目前爲止我的代碼:
FirstViewController.h
@interface FirstViewController : UIViewController
@property (strong) IBOutlet UISwitch * mySwitch;
@property (strong) IBOutlet UISlider *myTransitionSlide;
@property (nonatomic,retain) IBOutlet UILabel *labelTest;
myNSDataClass.h
#import <Foundation/Foundation.h>
#import <CoreBluetooth/CoreBluetooth.h>
@class FirstViewController;
@interface myNSDataClass : NSObject <UIApplicationDelegate,CBPeripheralManagerDelegate>
{
FirstViewController *firstViewController;
}
@property (nonatomic, retain) FirstViewController *firstViewController;
myNSDataClass.m
- (void)peripheralManager:(CBPeripheralManager *)peripheral didReceiveWriteRequests:(NSArray *)requests
{
self.firstViewController = [[FirstViewController alloc]init];
[[self.firstViewController labelTest]setText:@"text changed"];
[self.firstViewController.myTransitionSlide setValue:1];
[self.firstViewController.mySwitch setOn:NO animated:YES];
}
我知道問題來自FirstViewController的重新分配,但我不知道該怎麼辦。
這是迄今爲止最乾淨的解決方案,非常感謝您 –