0

我正在尝试在单击按钮时创建一个名为“添加注释”的简单弹出窗口,该弹出窗口有一个保存和取消按钮,用于保存用户创建的注释并取消弹出窗口。这是弹出课程

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

这就是我在视图控制器按钮操作中调用弹出窗口的方式

- (IBAction)addNotes:(id)sender {

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

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

4

1 回答 1

0

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

于 2013-09-17T13:05:32.237 回答