PDA

View Full Version : Method sequence




hervey
Dec 5, 2009, 07:44 PM
Three methods are called by a single UIButton, methods:A, B, and C. A is called on touchDown, B and C on touchUpInside. A is calculations used in method B, C pushes another viewController onto screen, displaying A and B's calculations. Everything works individually and sometimes together.

What are some strategies to make the sequence more reliable. NSTimer is possible but seems like a lot of code when I already have to much code.

I am new to Cocoa and would appreciate any direction.



chbeer
Dec 6, 2009, 06:18 AM
Can you explain why you are doing it so complicated? Why not simply do everything in one method?

drf1229
Dec 6, 2009, 08:51 AM
I think you need to look into NSTimer. An example looks like this:
NSTimer *t=[NSTimer scheduledTimerWithTimeInterval:0.03 target:self selector:@selector(onTimer) userInfo:nil repeats:YES];

[t fire] //Starts the timer
//And the method...
-(void)onTimer{
//The function

[t invalidate] //Stops the timer...
}

dejo
Dec 6, 2009, 12:46 PM
I think you need to look into NSTimer.
I think chbeer has it right. It all sounds over-complicated. Have touchUpInside call one method, which can then go ahead and call the other three. Something like this:
- (IBAction)buttonClicked:(id)sender {
[self A];
[self B];
[self C];
}

drf1229
Dec 6, 2009, 02:46 PM
I think chbeer has it right. It all sounds over-complicated. Have touchUpInside call one method, which can then go ahead and call the other three. Something like this:
- (IBAction)buttonClicked:(id)sender {
[self A];
[self B];
[self C];
}

Maybe, but if he wanted the events to be timed so he can put some sort of pause between each action NSTimer would be nice to know. It still would be a good idea to call them like that though.

hervey
Dec 6, 2009, 10:08 PM
I hear the chorus and will rework to minimize the number of methods. There are 18 methods on view #1, including the A,B,C mentioned previous. I did have things more centralized a long while back, but had a few problems (especially with the 2 SQL methods) that were solved by compartmentalization.

I am new to programing, and have spent a lot of time reading the docs about many things. It has been easy for me to get lost in the code.

The program is an aviation flight planner. It has a database of all the airports in the world that can be used by a turbojet aircraft, and includes the probable wind between any of these points based on the time of the year.

The user can select an aircraft, date and time for arrival -or- departure, and the appropriate date time is calculated, including Daylight Savings and Time Line issues.

Many of the components are working and my current challenge is to integrate them into a single program.

I thank everyone for their suggestions and will post whatever solution to this part of the puzzle.

Cheers.