我已经创建了一个图像视图,并将其分配给图像按钮,如下面的代码所示。一旦我点击图像它应该弹出但它不起作用。如果我尝试使用UIPopOverView它不工作。如何为按钮popovercontroller创建。
- (IBAction)showPopover:(UIButton *)sender
{
if(![popoverController isPopoverVisible]){
myPopOver = [[PopViewController alloc] initWithNibName:@"PopViewController" bundle:nil];
popoverController = [[[UIPopoverController alloc] initWithContentViewController:myPopOver] retain];
[popoverController setPopoverContentSize:CGSizeMake(299.0f,111.0f)];
[popoverController presentPopoverFromRect:CGRectMake(10, 10, 200, 200) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
else{
[popoverController dismissPopoverAnimated:YES];
}
}
- (void)viewDidLoad
{
[super viewDidLoad];
imageView=[[UIImageView alloc] initWithFrame:CGRectMake(10, 10,100, 100)];
imageView.image=[UIImage imageNamed:@"Dosa.jpg"];
CGRect textViewFrame = CGRectMake(10, 10, 300, 400);
textView = [[UITextView alloc] initWithFrame:textViewFrame];
textView.returnKeyType = UIReturnKeyDone;
textView.text = @"\n\n\n\n\n\n\n\nDOSA\nDosa, a common breakfast dish and street food, is rich in carbohydrates, and contains no sugar or saturated fats. ";
textView.backgroundColor=[UIColor whiteColor];
textView.editable=NO;
textView.delegate = self;
[self.view addSubview:textView];
[textView addSubview:imageView];
textView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"Indian.jpg"]];
textView.alpha = 0.9;
textView.font = [UIFont systemFontOfSize:15];
imageView.userInteractionEnabled = YES;
imageButton = [[UIButton alloc]init];
[imageButton setFrame:CGRectMake(0, 0, 100, 100)];
[imageButton addTarget:self action:@selector(showPopover:) forControlEvents:UIControlEventTouchUpInside];
[imageView addSubview:imageButton];
[imageButton release];
[imageView release];
[textView release];
if(mrowno==0)
{
imageView.image=[UIImage imageNamed:@"Dosa.jpg"];
textView.text = @"\n\n\n\n\n\n\n\nDOSA\nDosa, a common breakfast dish and street food, is rich in carbohydrates, and contains no sugar or saturated fats. ";
}
}
答案 0 :(得分:0)
试试这个,
popViewController.h
@protocol popViewControllerDelegate
@end
@interface PopViewController : UIViewController
{
id <popViewControllerDelegate> delegate;
}
@property (nonatomic,retain) id <popViewControllerDelegate> delegate;
@end
popViewController.m
@synthesize delegate;
popViewController.h
@interface viewController : UIViewController<popViewControllerDelegate>
{
}
- (IBAction)showPopover:(UIButton *)sender
{
UIButton *btn = (UIButton *)sender;
if(![popoverController isPopoverVisible]){
myPopOver = [[PopViewController alloc] initWithNibName:@"PopViewController" bundle:nil];
myPopOver.delegate=self;
popoverController = [[[UIPopoverController alloc] initWithContentViewController:myPopOver] retain];
[popoverController setPopoverContentSize:CGSizeMake(299.0f,111.0f)];
[popoverController presentPopoverFromRect:btn.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}}