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

Icestyle

macrumors member
Original poster
May 24, 2006
80
106
Vienna, Austria
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!
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
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.
 

Icestyle

macrumors member
Original poster
May 24, 2006
80
106
Vienna, Austria
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.

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.
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
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.

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.
 

ayasin

macrumors 6502
Jun 26, 2008
318
0
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).
 

Icestyle

macrumors member
Original poster
May 24, 2006
80
106
Vienna, Austria
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.
 

Icestyle

macrumors member
Original poster
May 24, 2006
80
106
Vienna, Austria
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
}
Thanks for that - it helped me out.
I wasn't sure about "self".
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.