我正在使用最新的 SDK 开发一个 iOS 5+ 应用程序,并且我有一个自UIView
定义的XIB
.
这是TopMenuView.h
:
#import <UIKit/UIKit.h>
@interface TopMenuView : UIView
@property (weak, nonatomic) IBOutlet UIButton *MenuButton;
@property (weak, nonatomic) IBOutlet UILabel *MenuLabel;
@property (weak, nonatomic) IBOutlet UIButton *SearchButton;
@property (weak, nonatomic) IBOutlet UIButton *ProfileButton;
@property (weak, nonatomic) IBOutlet UIButton *HomeButton;
@property (weak, nonatomic) UIViewController* parentController;
- (IBAction)MenuClicked:(id)sender;
- (IBAction)SearchClicked:(id)sender;
- (IBAction)ProfileClicked:(id)sender;
- (IBAction)HomeClicked:(id)sender;
+ (id)topMenuView;
@end
这是TopMenuView.m
:
#import "TopMenuView.h"
#import "SearchViewController.h"
#import "ProfileViewController.h"
#import "HomeViewController.h"
#import "SWRevealViewController.h"
@implementation TopMenuView
@synthesize parentController;
+ (id)topMenuView
{
TopMenuView* topView = [[[NSBundle mainBundle] loadNibNamed:@"TopMenuView"
owner:nil
options:nil] lastObject];
// make sure customView is not nil or the wrong class!
if ([topView isKindOfClass:[TopMenuView class]])
{
[topView setFrame:CGRectMake(0, 0, 320, 49)];
return topView;
}
else
return nil;
}
#pragma mark -
#pragma mark IBAction methods
- (IBAction)MenuClicked:(id)sender
{
[self.parentController.revealViewController revealToggle:sender];
}
- (IBAction)SearchClicked:(id)sender
{
SearchViewController* search =
[[SearchViewController alloc] initWithNibName:@"SearchViewController"
bundle:nil];
[self.parentController.revealViewController setFrontViewController:search];
}
- (IBAction)ProfileClicked:(id)sender
{
ProfileViewController* profile =
[[ProfileViewController alloc] initWithNibName:@"MyProfileViewController"
bundle:nil];
[self.parentController.revealViewController setFrontViewController:profile];
}
- (IBAction)HomeClicked:(id)sender
{
HomeViewController* home =
[[HomeViewController alloc] initWithNibName:@"HomeViewController"
bundle:nil];
[self.parentController.revealViewController setFrontViewController:home];
}
@end
我UIViewController
这样做是为了展示它:
- (void)viewDidLoad
{
[super viewDidLoad];
topMenuView = [TopMenuView topMenuView];
topMenuView.MenuLabel.text = @"Home";
topMenuView.parentController = self;
[self.view addSubview:topMenuView];
// Set the gesture to open the slide menu.
[self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];
}
这是观点:
此代码仅适用于 iPhone Retina 4 英寸模拟器。在 iPhone Retina 3.5 英寸和 iPhone 模拟器上,它不起作用。
问题是我点击任何“按钮”它什么都不做。没有 Touch Inside Up 事件被抛出(我在 IBAction 方法中设置了一个调试点)。
我还没有在真正的 iPhone 上测试它,因为我还没有开发者许可证。
发生了什么?为什么它在 iPhone 3.5 英寸上不起作用?