我想制作头文件Rimage.h和m我可以在任何地方使用但我在这里有问题 这是我的
Rimage.h
@class Rahul_imageplaceCordinatesViewController;
@interface Rimage : NSObject {
Rahul_imageplaceCordinatesViewController *vc;
}
-(void)addImageSubViewAtX:(CGFloat)x atY:(CGFloat)y;
@property (nonatomic,copy) Rahul_imageplaceCordinatesViewController *vc;
+(void)check1;
@end
这是我的.m
@implementation Rimage
@synthesize vc;
/// this method let you have image with given X n Y
- (void)addImageSubViewAtX:(CGFloat)x atY:(CGFloat)y {
CGRect myImageRect1 = CGRectMake(x, y, 30.0f, 30.0f);
UIImageView *myImage1 = [[UIImageView alloc] initWithFrame:myImageRect1];
[myImage1 setImage:[UIImage imageNamed:@"status_finish.gif"]];
myImage1.tag = 1000;
myImage1.userInteractionEnabled = YES;
[self.view addSubview:myImage1];
}
现在在我的mainVC
我这样打电话
- (void)viewDidLoad {
Rimage *hw = [[Rimage alloc] init];
//[hw check1];
[Rimage check1];
[hw addImageSubViewAtX:160.0 atY:190.0];
}
但我无法显示那个图像,我不知道为什么:(
答案 0 :(得分:0)
首先我注意到你的@property是你在vc中制作ViewController的“副本”,我怀疑这是一个坏主意,你只想分配或保留它。
其次,在addImageSubViewAtX中,你有:
[self.view addSubview:myImage1];
但那里的自我是什么?这是Rimage的例子。我猜你也许是想在vc中将图像添加到视图中?我没有看到vc曾经用在你提供的代码中,它的用途是什么?
[vc.view addSubview:myImage1];