-1

我在尝试在视图中弹出图像时遇到问题。我用图像创建了一个新的 UIView 子类(UIViewImageOverlay.m)。

UIViewImageOverlay.m

//  ImageOverlay.m
//  ButtonPopup
//
//

#import "UIViewImageOverlay.h"

@implementation UIViewImageOverlay

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
    }
    return self;
}


// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    CGContextRef contextRef = UIGraphicsGetCurrentContext();
    UIImage *myImage = [UIImage imageNamed:@"test.jpeg"];
    int w = myImage.size.width;
    int h = myImage.size.height;
    CGContextDrawImage(contextRef, CGRectMake(0, 0, w, h), myImage.CGImage);
    CGContextRelease(contextRef);
}


@end

在我的 ViewController.mi 中有一个按钮pushPush来加载视图,但尝试给出警告

//  ViewController.m
//  ButtonPopup
//
//

#import "ViewController.h"
#import "UIViewImageOverlay.h"

@interface ViewController ()

@end

@implementation ViewController
@synthesize viewImageOverlay;



- (void)viewDidLoad
{
    [super viewDidLoad]; // static
}

- (void)viewDidUnload
{

    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
    } else {
        return YES;
    }
}

- (IBAction)pushPush:(id)sender {
    [self.view addSubview:self.viewImageOverlay];
}
@end

视图控制器.h

//  ViewController.h
//  ButtonPopup
//

#import <UIKit/UIKit.h>
@class UIViewImageOverlay;


@interface ViewController : UIViewController {
    UIViewImageOverlay *viewImageOverlay;
}

@property(nonatomic, retain) UIViewImageOverlay *viewImageOverlay; 
- (IBAction)pushPush:(id)sender;
@end

UIViewImageOverlay.h

//  ImageOverlay.h
//  ButtonPopup
//
//

#import <UIKit/UIKit.h>

@interface UIViewImageOverlay : UIView

@end

[self.view addSubview:self.viewImageOverlay];报告Incompatible pointer types sending 'UIViewImageOverlay *' to parameter of type 'UIView *'

提前致谢。

4

2 回答 2

1

声明实例变量 viewImageOverlay 并将其定义为属性

于 2012-04-22T15:05:30.177 回答
1

您在控制器的头文件 ( @class UIViewImageOverlay) 中有一个前向类声明。它掩盖了正确的实现。

包含UIViewImageOverlay.h在控制器的实现文件中

于 2012-04-22T15:10:04.627 回答