Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Poy77

macrumors newbie
Original poster
Sep 5, 2010
18
0
I have looked at MoveMe example.
Now I tried to do almost same, but I don't want to use View class.

I created View-Based Application project and added some lines:
Code:
@interface TestViewController : UIViewController {
    UIImage *mainImage;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    mainImage = [UIImage imageNamed:@"TestImage.png"];
    [mainImage drawAtPoint:(CGPointMake(130.0, 130.0))];
}

Still application window is grey. I am trying to understand deeply what are those terms (Uview, ViewController, ...), and that's why I wanted to do at this way.

I have lot of experience from C-language but not from Objective-C. So some examples are very easy for me because they contains c-functions, but not that beginning.
...and sorry my English :eek:
 
You can only use the drawInRect: / drawAtPoint: methods in a drawing context. The most common way to achieve this is by subclassing UIView and overriding drawRect: (although you could simply use a UIImageView for your cause).

In the end, you'll have to use a UIView – either your own or an existing one like UIImageView :)
 
I have looked at MoveMe example.
Now I tried to do almost same, but I don't want to use View class.

I created View-Based Application project and added some lines:
Code:
@interface TestViewController : UIViewController {
    UIImage *mainImage;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    mainImage = [UIImage imageNamed:@"TestImage.png"];
    [mainImage drawAtPoint:(CGPointMake(130.0, 130.0))];
}

Still application window is grey. I am trying to understand deeply what are those terms (Uview, ViewController, ...), and that's why I wanted to do at this way.

I have lot of experience from C-language but not from Objective-C. So some examples are very easy for me because they contains c-functions, but not that beginning.
...and sorry my English :eek:


Code:
- (void)viewDidLoad {
    [super viewDidLoad];
    mainImage = [UIImage imageNamed:@"TestImage.png"];
    UIImageView *imageView= [[UIImageView alloc] initWithImage:mainImage];
    [self.view addSubView:imageView];
}

Try this
 
Code:
- (void)viewDidLoad {
    [super viewDidLoad];
    mainImage = [UIImage imageNamed:@"TestImage.png"];
    UIImageView *imageView= [[UIImageView alloc] initWithImage:mainImage];
    [self.view addSubView:imageView];
}

Try this
It said "warning: 'UIView' may not respond to '-addSubView:'" I don't know why.
I also tried to add UIView subclass but I don't know how to addsubview from UIViewController subclass (which was generated by xcode).
So instead of using View-Based applicaiton project should I use Windows-Based application project? Is it only way? I have once did it, but I don't remember what I did in interface builder.
 
It said "warning: 'UIView' may not respond to '-addSubView:'" I don't know why.
I also tried to add UIView subclass but I don't know how to addsubview from UIViewController subclass (which was generated by xcode).
So instead of using View-Based applicaiton project should I use Windows-Based application project? Is it only way? I have once did it, but I don't remember what I did in interface builder.

Sorry I was typing really quick on my ipad.


Code:
- (void)viewDidLoad {
[super viewDidLoad];
mainImage = [UIImage imageNamed:@"TestImage.png"];
UIImageView *imageView = [[UIImageView alloc] initWithImage:mainImage];
[self.view addSubview:imageView];
[imageView release];
}


The error you received was my fault:
Code:
//bad code
[self.view addSubView:imageView];

should have been

Code:
//proper code
[self.view addSubview:imageView];

I also added the release to make it proper.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.