-6

I am beginner at Objective-c and iOS application develop. And i want to take your suggestions about my way of implementation codes. I am using view controllers for implement all my methods in that way:

- (void)viewDidLoad
{
    [super viewDidLoad];

[self performSelector:@selector(Method1) withObject:self afterDelay:0.1];

[self performSelector:@selector(Method2) withObject:self afterDelay:0.2];

[self performSelector:@selector(Method3) withObject:self afterDelay:0.3];

[self performSelector:@selector(Method4) withObject:self afterDelay:0.4];
}

Is that way, a true approach for a stabile application.

ananana
  • 15
  • 7
  • 3
    What are you trying to do? – DrummerB May 12 '13 at 18:56
  • It is my general style of coding. Because i am beginner at Objective-C i just want to confirm that style before come across with a unstabile application – ananana May 12 '13 at 19:01
  • 2
    Sorry to disappoint you but this does not look like a good approach. Why are you calling methods after a delay? – Marcin Kuptel May 12 '13 at 19:03
  • because i want to be sure which row my methods are implemented. will delays cause any performance issue. I am asking that question because i do not have any experience writing codes and i can not predict what my code cause in terms of memory management etc. – ananana May 12 '13 at 19:14
  • @user2343249 The methods you call are executed sequentially (one after the other). When methods are executed at the same time, that's called multithreading and it's actually quite difficult to do usually, you won't do it by accident. – DrummerB May 12 '13 at 19:53

2 Answers2

4

You don't have to use (performSelector:withObject:afterDelay:) all the time ! Say you have two methods implemented in your viewController :

-(void) firstMethod 
{
   //do stuff here
}

-(void) secondMethod 
{
   //do stuff here
}

you can call those methods this way :

- (void)viewDidLoad
{
    [super viewDidLoad];

    [self firstMethod];

    [self secondMethod];

}

Now what we have is when your app is about to load its viewControllers's view, firstMethod is called then the second ;)

hellboy1738
  • 144
  • 3
3

This is not the normal way to do anything in Objective-C.

In Objective-C you call methods using this syntax: [object method];

In your case that would look like this:

- (void)viewDidLoad {
   [super viewDidLoad];
   [self method1]; 
   [self method2];
   [self method3];
   [self method4];
}

Please read these:

DrummerB
  • 39,814
  • 12
  • 105
  • 142