【发布时间】:2012-01-16 18:25:02
【问题描述】:
我试图在我的UIPopover 中使用一个按钮在我的主要UIViewController 中创建一个UITextView,我的代码看起来像这样(PopoverView.h 文件):
@protocol PopoverDelegate <NSObject>
- (void)buttonAPressed;
@end
@interface PopoverView : UIViewController <UITextViewDelegate> { //<UITextViewDelegate>
id <PopoverDelegate> delegate;
BOOL sendDelegateMessages;
}
@property (nonatomic, retain) id delegate;
@property (nonatomic) BOOL sendDelegateMessages;
@end
然后在我的PopoverView.m 文件中:
- (void)viewDidLoad
{
[super viewDidLoad];
UIButton * addTB1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
addTB1.frame = CGRectMake(0, 0, 100, 50);
[addTB1 setTitle:@"Textbox One" forState:UIControlStateNormal];
[self.view addSubview:addTB1]; // Do any additional setup after loading the view from its nib.
[addTB1 addTarget:self action:@selector(buttonAPressed)
forControlEvents:UIControlEventTouchUpInside];
}
- (void)buttonAPressed
{
NSLog(@"tapped button one");
if (sendDelegateMessages)
[delegate buttonAPressed];
}
还有我的MainViewController.m:
- (void)buttonAPressed {
NSLog(@"Button Pressed");
UITextView *textfield = [[UITextView alloc] init];
textfield.frame = CGRectMake(50, 30, 100, 100);
textfield.backgroundColor = [UIColor blueColor];
[self.view addSubview:textfield];
}
我正在使用委托协议来链接 popover 和 ViewController,但我一直坚持如何让我的 BOOL 语句链接 PopoverView 和 MainViewController 中的 -(void)buttonAPressed,这样当我按下按钮时弹出一个文本视图出现在主 VC 中。我该怎么做呢?
【问题讨论】:
标签: ios uiviewcontroller delegates uitextview uipopovercontroller