我已經加載了帶有單獨的XIB(SecondView.xib)的UIView(FirstView.m),但該XIB中的按鈕會使應用程序崩潰。這些按鈕的代碼(IBOutlet & IBAction)位於SecondView.m中。UIView加載XIB的按鈕不起作用
我是否需要將SecondView.m中的代碼指向FirstView.m?我嘗試使用#import和@class ...但不成功。
我使用的代碼是完全有效的......我敢肯定,這個問題與XIB被加載到UIView中有關......然後可能失去與實現文件的連接。思考?
在此先感謝!
FirstView.h
#import <UIKit/UIKit.h>
@interface FirstView : UIViewController {
IBOutlet UIView *SecondViewPopUP;
IBOutlet UIButton *openBTN;
}
@property (nonatomic, retain) UIView *SecondViewPopUP;
@property (nonatomic, retain) IBOutlet UIButton *openBTN;
-(IBAction)showPopUp:(id)sender;
FirstView.m
@synthesize SecondViewPopUP;
@synthesize openBTN
- (void)viewDidLoad {
SecondViewPopUP.alpha = 0;
// Add IncidentsViewController to view
SecondView *SecondV=[[SecondView alloc] init];
SecondV.view.frame = CGRectMake(0, 0, 262, 269);
SecondV.view.clipsToBounds = YES;
[SecondViewPopUP addSubview:SecondV.view];
SecondViewPopUP.frame = CGRectMake(0, 76, 262, 269);
[SecondV release];
}
-(IBAction)showPopUp:(id)sender {
NSLog(@"Stats Button was pressed");
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.4];
SecondViewPopUP.alpha = 1;
[UIView commitAnimations];
}
SecondView.h
#import <UIKit/UIKit.h>
@interface ShareViewController : UIViewController {
IBOutlet UIButton *share_facebook;
IBOutlet UIButton *share_twitter;
}
@property (nonatomic, retain) IBOutlet UIButton *share_facebook;
@property (nonatomic, retain) IBOutlet UIButton *share_twitter;
-(IBAction)shareOnFB:(id)sender;
-(IBAction)shareOnTwitter:(id)sender;
SecondView.m
@synthesize share_twitter, share_facebook;
- (void)viewDidLoad {
[super viewDidLoad];
}
-(IBAction)shareOnFB:(id)sender {
NSLog(@"Shared on FB");
}
-(IBAction)shareOnTwitter:(id)sender {
NSLog(@"Shared on Twitter");
}
請張貼一些代碼。 – David
新增...大部分都是僞造的......我不想複製我所有的代碼......但它是重要的東西。 –
嘗試NSLogging按鈕的插座,確保它不是無 – MCannon