此代码仅适用于iPhone Retina 4英寸模拟器

时间:2013-10-16 16:10:22

标签: iphone ios objective-c ios-simulator

我正在使用最新的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];
}

这就是观点:

enter image description here

此代码仅适用于iPhone Retina 4英寸模拟器。在iPhone Retina 3.5英寸和iPhone模拟器上,它不起作用。

问题是我点击任何“按钮”它什么都不做。抛出No Touch Inside Up事件(我在IBAction方法中设置了一个调试点)。

我没有在真正的iPhone上测试它,因为我还没有开发者许可证。

发生了什么事?为什么它不适用于3.5英寸的iPhone?

2 个答案:

答案 0 :(得分:0)

您可能有另一个视图覆盖了您的按钮。检查xib文件,查看系统在屏幕大小不同时可能正在展开的视图。

答案 1 :(得分:0)

我遇到了同样的问题。一切正常,直到我取消选中&#34;使用AutoLayout&#34;故事板中的按钮。我有UIView按钮放在上面。并有与此按钮相关的操作。然后在iPhone Retina 3.5英寸模拟器中它没有响应该动作。 最后,我在故事板中找到了解决方案。它设置我的视图高度,按钮位置为0.我不知道为什么。所以我只是以编程方式指定其高度。 希望这会有所帮助!