Objective C first program issue

Discussion in 'iOS Programming' started by samuelbird, Apr 21, 2014.

  1. samuelbird macrumors newbie

    Joined:
    Apr 21, 2014
    #1
    Hello, I am very new to objective c and have decided to learn some so I can try and make some apps and what not for fun. I am very young but I know a fair bit of Java, quite a bit of EE standard web dev, and also a little Python. Anyway, I was following a short tutorial by this guy and I have come across an issue. My ViewController.m is here:

    Code:
    //
    //  ViewController.m
    //  basicsvapp
    //
    //  Created by Samuel Bird on 19/04/2014.
    //  Copyright (c) 2014 Samuel Bird. All rights reserved.
    //
    
    #import "ViewController.h"
    
    @interface ViewController ()
    
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
    	// Do any additional setup after loading the view, typically from a nib.
        
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 50)];
        label.text = @"Hello Again";
        
        [self.view addSubView:label];
    
    - (void)didReceiveMemoryWarning
    {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    
    @end
    After
    Code:
    [self.view addSubView:label];
    , there is the error "No visible @interface for 'UIView' declares the selector 'addSubView'" which I have read about and is quite common. However, I am not sure how to fix it. I would appreciate some advice.

    Sam

    P.s. Just in case, my ViewController.h is here:

    Code:
    #import <UIKit/UIKit.h>
    
    @interface ViewController : UIViewController
    
    @end
    
     
  2. waterskier2007, Apr 21, 2014
    Last edited: Apr 21, 2014

    waterskier2007 macrumors 68000

    waterskier2007

    Joined:
    Jun 19, 2007
    Location:
    White Lake, MI
    #2
    It is

    Code:
    addSubview
    
    Not

    Code:
    addSubView
    
    (capitalization)

    edit: xcode should autocomplete this as you type "[self.view addSu..."
     
  3. samuelbird thread starter macrumors newbie

    Joined:
    Apr 21, 2014
  4. iMacFarlane macrumors 65816

    iMacFarlane

    Joined:
    Apr 5, 2012
    Location:
    Adrift in a sea of possibilities
    #4
    Not silly. You learned. Mission accomplished! :)
     
  5. MattInOz macrumors 68030

    MattInOz

    Joined:
    Jan 19, 2006
    Location:
    Sydney
    #5
    As already said there are no silly mistakes if you learn from them but
    also get use to it, you'll make 1000's of silly mistakes while learning. :)

    Probably just as many once you've learnt.
     
  6. Dranix macrumors 6502a

    Dranix

    Joined:
    Feb 26, 2011
    Location:
    Gelnhausen, Germany
    #6
    May I ask why you are creating the UILabel by code instead of using interface builder?
     
  7. samuelbird thread starter macrumors newbie

    Joined:
    Apr 21, 2014
    #7
    It was just me getting to grips. I wanted to learn about the different UI elements. I have been using interface builder since. :)
     

Share This Page