How to make a counter?

How do I make counter to count how many times a UIButton was tap on the iphone?

macbook (late 2008) 2 GHz intel Core 2 Duo Processor, 2 GB RAM, Mac OS X (10.6.3), iPod Nano (5th Gen)

Posted on Apr 28, 2010 6:04 PM

Reply
10 replies

Apr 29, 2010 7:46 PM in response to X- Developer

Start with the View-based App template:

// XDevViewController.h
@interface XDevViewController : UIViewController {
int currentCount;
}
- (IBAction)incrementCount;
@end
// XDevViewController.m
#import "XDevViewController.h"
@implementation XDevViewController
- (IBAction)incrementCount {
currentCount++;
NSLog(@"currentCount=%d", currentCount);
}
@end

Open XdevViewController.xib, add a UIButton object to the view, and connect the (Touch Up Inside) event of the button to the incrementCount action of File's Owner.

This is pretty basic stuff, X. In fact I just peeked at my ChicagoScope and saw Trakesh rolling his eyes, since he already posted enough for a beginner to code from. So I really, really want you to get a good book, such as +Beginning iPhone 3 Development: Exploring the iPhone SDK+ by LaMarch and Mark. Ok?

- Ray

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

How to make a counter?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.