Objective-C'de, bir düğmeye her basıldığında bir sayacı artıran basit bir kod bloğum var. Günlüklerim ve hatta arayüzdeki güncellemeler, bir yerine 4'lük bir artış gösteriyor. Bu sadece biçimlendirmemle (% d kullanıyorum) veya eksik olduğum başka bir şeyle ilgili bir sorun mu? Benim tahminim "% d" ile yatıyor ama Objective-C için yeni ve emin değilim. . (Not, ben de denedim "sayaç + = 1;" aynı sonucuObjective-C'de, bu artış neden 1 yerine 4 ile mi?
int counterValue = 0;
NSLog(@"Count at init: %d",counterValue);
...
-(IBAction)pushButton {
NSLog(@"Count (Pre-Push) = %d",counterValue);
counterValue++;
NSLog(@"Count (Post-Push) = %d",counterValue);
}
çıkışını aşağıdaki gibidir:
2010-02-20 18:39:39.125 My App[37536:207] Count at init: 0
2010-02-20 18:39:39.845 My App[37536:207] Count (Pre-Push) = 0
2010-02-20 18:39:39.846 My App[37536:207] Count (Post-Push) = 4
2010-02-20 18:39:40.165 My App[37536:207] Count (Pre-Push) = 4
2010-02-20 18:39:40.166 My App[37536:207] Count (Post-Push) = 8
2010-02-20 18:39:40.727 My App[37536:207] Count (Pre-Push) = 8
2010-02-20 18:39:40.728 My App[37536:207] Count (Post-Push) = 12
Bir nit tarafından tarafındanartım (IBAction) doWhatever Eylem yöntemleri' olmalıdır. – Wevah
@Wevah: gerçekten değil. Tek argüman formu en popüler olsa da, tüm bu yöntem imzaları eylem yöntemleri için eşit olarak geçerlidir: (1) '- (void) eylem', (2)' - (void) eylemi: (id) gönderen ’, (3) '- (void) eylemi: (id) gönderici içinEkran: (UIEvent *) olayı '. Kaynak: http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIControl_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40006779-RH2-SW28 –
Ah, haklısınız . Görünüşe göre başka bir UIKit/AppKit farkı. (.S)) .h dosyamda – Wevah