0

私は画像ビューを作成し、それを以下のコードに示すimagebuttonに割り当てます.画像をクリックするとポップオーバーが表示されますが、機能しません.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. ";


}
}
4

1 に答える 1

0

これを試して、

popViewController.h

@protocol popViewControllerDelegate
@end
@interface PopViewController : UIViewController
{
  id <popViewControllerDelegate> delegate;
}
@property (nonatomic,retain) id <popViewControllerDelegate> delegate;
@end

popViewController.m

  @synthesize delegate;

viewcontroller.h

 popViewController.h
 @interface viewController : UIViewController<popViewControllerDelegate>
 {

 }

viewcontroller.m

- (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];
}}  
于 2013-03-04T10:23:55.690 に答える