Image question

Discussion in 'iOS Programming' started by Poy77, Sep 23, 2010.

  1. Poy77 macrumors newbie

    Joined:
    Sep 5, 2010
    #1
    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:
     
  2. (marc) macrumors 6502a

    (marc)

    Joined:
    Sep 15, 2010
    Location:
    the woods
    #2
    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 :)
     
  3. Sykte macrumors regular

    Joined:
    Aug 26, 2010
    #3

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

    Joined:
    Sep 5, 2010
    #4
    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.
     
  5. Sykte macrumors regular

    Joined:
    Aug 26, 2010
    #5
    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.
     
  6. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #6
    The lesson to take away from Sykte's mistake: Objective-C is case-sensitive! So, be precise.
     
  7. Sykte macrumors regular

    Joined:
    Aug 26, 2010
    #7

    and Xcode wouldn't run well on IPad.


    :)
     
  8. ianray macrumors 6502

    Joined:
    Jun 22, 2010
    Location:
    @
    #8
    ...maybe one day it will ;)
     

Share This Page