Calling a "method"

Discussion in 'iOS Programming' started by Icestyle, Oct 15, 2008.

  1. Icestyle macrumors member

    Icestyle

    Joined:
    May 24, 2006
    Location:
    Vienna, Austria
    #1
    Hi!

    First off I'm not sure if it's called method.

    I'm used to Visual Basic programming (wasn't my decision, had to do it).

    Let's say I have something like this:
    Code:
    Private Sub cmbinfo_Click(Index as Integer)
    listfill
       //do some additional crap  
    End Sub
    
    Where listfill would be this:
    Code:
    Private Sub listfill()
       //do large amount of crap
    End Sub
    
    That would work in Visual Basic.

    So what's the problem?
    I have absolutely no clue how to do something like that in Cocoa.
    Used Google with no luck (maybe it's not called method?)

    I have a timer to reload some data.
    Every 30 seconds I'd like to do something (100 lines).

    But I would also like the user to do the refresh manually with a button.
    Sure, I could (didn't try this) link the button to the method the timer fires.

    The problem: I need the manual refresh to trigger the same code as the timer refresh but also some additional code.


    How can I do this in Cocoa
    Thanks!
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    Basically it seems like you are used to procedural programming and you need to go back to the start and learn about object-oriented programming before you tackle the specifics of objective C. You don't call methods on their own: you pass a message to a specific instance of a class (an object). The object and the method are interlinked.

    Go and learn to crawl before you try running. There are plenty of introductions to OO programming out there.
     
  3. Icestyle thread starter macrumors member

    Icestyle

    Joined:
    May 24, 2006
    Location:
    Vienna, Austria
    #3
    Exactly what I didn't need.
    Visual Basic is object oriented.

    You could help me understand some things better:

    What is a class?
    What is an object?
    What is a method?

    I'm not 100% sure what is what.

    I know that I can pass a value to a variable in another method and get an answer.
    This doesn't help me at all.
    As I said I have like 100 lines of code to execute and I have no clue how to connect these lines to another method.
     
  4. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #4
    Unless it's VB.net then Visual Basic isn't Object-Oriented. It kind of pretends to be but it's not. If you don't know the difference between a class, an object and a method my advise still stands: you need to learn the basic theory.
     
  5. ayasin macrumors 6502

    Joined:
    Jun 26, 2008
    #5
    The answer to your immediate question is this:

    Code:
    -(void)cmbinfo_Click:(int)Index {
       [self listfill];
       //do some additional crap
    }
    
    -(void)listfill {
       //do large amount of crap
    }
    
    With that said VB is only object oriented as a hack (and even then, in the loosest possible sense unless you're talking about VB.NET). I would say that if you can't figure out how to send a message to self you really need to start with an elementary objective c book rather than try to jump right into porting an app from VB. That may sound harsh, but it'll save you a lot of headache later (and a lot of user complaints as well most likely).
     
  6. Icestyle thread starter macrumors member

    Icestyle

    Joined:
    May 24, 2006
    Location:
    Vienna, Austria
    #6
    My native language isn't English.
    That's why I'm not sure about the names.

    I was talking about VB6 and VB.net.
    I also know Delphi.

    So I think I can assume I know the basics.

    I also have an Objective C/Cocoa Book lying around but it didn't help me out with this specific question.

    The Apple Developer sites are very detailed but still often missing a proper example.

    Some of the theory there is hard to understand without some "real" code.

    btw: I'm not porting any app - the app I'm writing only makes sense on a mobile device.
     
  7. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #7
    This may sound harsh, but if you are asking questions like that, then no, you do not know the basics. Grab that Objective-C book you have and read the whole thing. Then you will be much better informed.
     
  8. Icestyle thread starter macrumors member

    Icestyle

    Joined:
    May 24, 2006
    Location:
    Vienna, Austria
    #8
    Thanks for that - it helped me out.
    I wasn't sure about "self".
     

Share This Page