我已經創建了一個圖像視圖,並將其分配給imagebutton它顯示在下面的code.Once我點擊圖像應該得到popover,但它不工作。如果我嘗試使用UIPopOverView它不工作。如何創建按鈕popovercontroller。如何使popoverview圖像點擊imagebutton
- (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. ";
}
}
您的酥料餅的大小是(200200),但[in_sender.superview SETFRAME:CGRectMake(0,0,300,500)]; – NANNAV 2013-03-04 10:11:37
您必須訪問popover委託myPopOver.delegate = self; – Ravindhiran 2013-03-04 10:25:33