我创建了一个图像视图,并将其分配给下面代码中显示的图像按钮。一旦我单击图像,它应该会弹出但它不起作用。如果我尝试使用 UIPopOverView 它不起作用。如何创建按钮弹出控制器。
- (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. ";
}
}