我目前正在使用一個Objective-C程序來編碼和解碼消息。雖然我有一個問題。我有一個名爲Sys_Type的NSString,它存儲系統設置爲的設置(編碼或解碼)。當我的NSLog NSString的在設置當我把它在功能上正確的值不過返回其值的函數:NSString通過方法賦值,但另一種方法無法檢索到這個值(Objective C)
- (IBAction爲)addData:(ID)發送
該值爲空。我不知道爲什麼會發生這種情況,有人可以幫忙嗎?
我已附加AppDelegate.h & .m,因爲這是具有兩種功能的類。
AppDelegate.h
#import <Cocoa/Cocoa.h>
@interface AppDelegate : NSObject <NSApplicationDelegate> {
@private
IBOutlet NSBox *Box;
IBOutlet NSTextField *Label;
IBOutlet NSButton *Encode;
IBOutlet NSButton *Decode;
NSString *data;
NSString *Sys_Type;
}
@end
AppDelegate.m
#import "AppDelegate.h"
#include "MasterView.h"
@interface AppDelegate()
@property (weak) IBOutlet NSWindow *window;
@property (nonatomic, strong) IBOutlet MasterView *masterView;
@property (assign) IBOutlet NSWindow *textInput_Sheet;
@end
@implementation AppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
// Create the master View
self.masterView = [[MasterView alloc] initWithNibName:@"MasterView" bundle:nil];
}
- (void)applicationWillTerminate:(NSNotification *)aNotification {
// Insert code here to tear down your application
}
- (IBAction)Encode:(id)sender {
Sys_Type = @"ENCODE";
// Hide system setup
Box.hidden = true;
Label.hidden = true;
Encode.hidden = true;
Decode.hidden = true;
// Add the view to the Window's content view
[self.window.contentView addSubview:self.masterView.view];
self.masterView.view.frame = ((NSView*)self.window.contentView).bounds;
// Set view to encode
[self.masterView SetType:Sys_Type];
NSLog(@"Sys: %@",Sys_Type);
}
- (IBAction)Decode:(id)sender {
Sys_Type = @"DECODE";
// Hide system setup
Box.hidden = true;
Label.hidden = true;
Encode.enabled = false;
Encode.hidden = true;
Decode.enabled = false;
Decode.hidden = true;
// Add the view to the Window's content view
[self.window.contentView addSubview:self.masterView.view];
self.masterView.view.frame = ((NSView*)self.window.contentView).bounds;
// Set view to encode
[self.masterView SetType:Sys_Type];
NSLog(@"Sys: %@",Sys_Type);
}
- (void)clearView {
[self.window.contentView removeView:self.masterView.view];
}
- (IBAction)Reset:(id)sender {
NSLog(@"reset fired");
// Show system setup
Box.hidden = false;
Label.hidden = false;
Encode.enabled = true;
Encode.hidden = false;
Decode.enabled = true;
Decode.hidden = false;
// Clear view
[self clearView]; // This isn't working, this is another issue, but not the main one :)
}
- (IBAction)addData:(id)sender {
NSLog(@"Button Fired");
NSLog(@"Sys: %@",Sys_Type);
/* * * * * * * * * * * * * * *
* Key: *
* 0 - MasterView Data Adder *
* 1 - Text input ok *
* 2 - File input ok *
* * * * * * * * * * * * * * */
if ([Sys isEqualToString:@"ENCODE"]) {
NSLog(@"Fired");
// This is where the specific sheet will be loaded
} else if ([Sys_Type isEqualToString:@"DECODE"]) {
}
}
- (IBAction)Add_Image:(id)sender {
}
- (IBAction)Start_Sys:(id)sender {
}
@end
非常感謝你提前:d
你還沒有說清楚。 –
(Sys_Type的值應該如何奇妙地從AppDelegate跳轉到MasterView?) –
請參閱[創建最小,完整和可驗證的示例]中的「最小」部分(http://stackoverflow.com/help/) MCVE)。 –