弹出窗口没有出现在iOS中

时间:2013-09-17 11:40:12

标签: ios objective-c popup uipopovercontroller xcode4.6

我正在尝试在按钮单击上创建一个名为Add Notes的简单弹出窗口,其中有一个保存和取消按钮,用于保存用户创建的注释并取消弹出窗口。这是弹出类

AddNotesPopUp.h

#import <UIKit/UIKit.h>
#import "UIImage+Buttons.h"


typedef enum AddNotesViewType
{
    AddNotesPopUpSimple
}AddNotesPopUpType;

@protocol AddNotesDelegate<NSObject>

@optional
-(void)saveButtonClicked:(id) popUp;
-(void)cancelAddButtonClicked:(id)popUp;
@end

@interface AddNotesPopUp : UIView

@property AddNotesPopUpType atype;
@property (nonatomic,assign) id <AddNotesDelegate> delegate;

-(id)initWithDelegate:(id)parent type:(AddNotesPopUpType) type;

@property (weak, nonatomic) IBOutlet UIView *popView;
@property (strong, nonatomic) IBOutlet UIButton *titleButton;


@property (weak, nonatomic) IBOutlet UIButton *cancelAddButton;
@property (weak, nonatomic) IBOutlet UIButton *saveButton;
@property (weak, nonatomic) IBOutlet UITextView *textArea;


- (IBAction)saveButtonAction:(id)sender;

- (IBAction)cancelButtonAction:(id)sender;

-(void)show;
-(void)hide;

@end

AddNotesPopUp.m

#import "AddNotesPopUp.h"
#import <QuartzCore/QuartzCore.h>


@implementation AddNotesPopUp

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        self=(AddNotesPopUp*)[[[NSBundle mainBundle] loadNibNamed:@"AddNotesPopUp" owner:nil options:nil] lastObject];
    }
    return self;
}
-(id)initWithDelegate:(id)parent type:(AddNotesPopUpType) type
{

    if (self = [super initWithFrame:CGRectMake(0, 0, 300, 300)])
    {
        // Initialization code
          self=(AddNotesPopUp*)[[[NSBundle mainBundle] loadNibNamed:@"AddNotesPopUp" owner:nil options:nil] lastObject];
    }
    self.delegate=parent;
    self.atype=type;
    UIViewController *parentView=(UIViewController*)parent;
    [parentView.view addSubview:self];
         if (type==AddNotesPopUpSimple)
        {
    [self.titleButton setImage:[UIImage buttonWithText:@"Add Notes" fontSize:15 bold:YES buttonSize:self.titleButton.frame.size baseColor:[UIColor colorWithRed:73.0/255.0 green:90.0/255.0 blue:100.0/255.0 alpha:1] downTo:[UIColor colorWithRed:57.0/255.0 green:70.0/255.0 blue:77.0/255.0 alpha:1]] forState:UIControlStateNormal];
    [self.saveButton setImage:[UIImage buttonWithTextAlignCenter:@"Save" fontSize:15 bold:YES buttonSize:self.saveButton.frame.size baseColor:[UIColor colorWithRed:117.0/255.0 green:185.0/255.0 blue:83.0/255.0 alpha:1] downTo:[UIColor colorWithRed:95.0/255.0 green:144.0/255.0 blue:64.0/255.0 alpha:1]] forState:UIControlStateNormal];
    [self.cancelAddButton setImage:[UIImage buttonWithTextAlignCenter:@"Cancel" fontSize:15 bold:YES buttonSize:self.cancelAddButton.frame.size baseColor:[UIColor colorWithRed:174.0/255.0 green:174.0/255.0 blue:174.0/255.0 alpha:1] downTo:[UIColor colorWithRed:124.0/255.0 green:124.0/255.0 blue:124.0/255.0 alpha:1]] forState:UIControlStateNormal];
        }


    self.popView.layer.masksToBounds=YES;
    self.popView.layer.cornerRadius=5.0f;
    self.popView.layer.borderWidth=1.0f;
    self.popView.layer.borderColor=[[UIColor blackColor]CGColor];
    self.popView.hidden=YES;


    self.hidden=YES;
    self.textArea.hidden=YES;


    return self;
}

-(void)show
{
    self.popView.hidden=NO;
    self.textArea.hidden=NO;
    [self.popView setTransform:CGAffineTransformMakeScale(0.1,0.1)];
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.25];
    [self.popView setTransform:CGAffineTransformMakeScale(1.0,1.0)];
    [UIView commitAnimations];


}

-(void) hide
{
    self.popView.hidden=YES;
}

- (IBAction)saveButtonAction:(id)sender {
    [self.delegate saveButtonClicked:self];
}

- (IBAction)cancelButtonAction:(id)sender {

    [self.delegate cancelAddButtonClicked:self];
}
@end

这就是我在viewcontroller按钮操作中调用弹出窗口的方法

- (IBAction)addNotes:(id)sender {

    AddNotesPopUp *pop=[[AddNotesPopUp alloc] initWithDelegate:self type:AddNotesPopUpSimple];
    [pop show];
}

我已经检查过断点并且执行成功通过initwithDelegate并在AddNotesPopUp.m中显示方法但弹出窗口没有显示,我在这里缺少什么?我在我的viewcontroller中添加了AddNotesPopUp的委托和类,我也没有收到任何错误。我正在使用Xcode 4.6。有什么建议吗?

1 个答案:

答案 0 :(得分:0)

原来这是一个简单的问题,我只需要添加 self.hidden = NO;在show方法