Monday, 15 August 2011

objective c - How to add 1 to Variable with Button Click? -



objective c - How to add 1 to Variable with Button Click? -

i want add together 1 variable each time button clicked, instead 10 digit number appears. doing wrong code below?

-(ibaction)recorddata:(id)sender { int randomnumber; randomnumber = randomnumber + 1; nsstring *myrandomnumber = [nsstring stringwithformat:@"%i", randomnumber]; nsstring *completedata = [[nsstring alloc] initwithformat:dataview.text]; completedata = [completedata stringbyappendingstring: @"\n"]; completedata = [completedata stringbyappendingstring:myrandomnumber]; dataview.text = completedata; }

make

int randomnumber

either static or declare instance variable.

what doing creating new varialbe each time when recorddata invoked. plus not initialize it. local variables not initialized. instance variables initialized 0/nil. result variable has random content (as name suggests anyway :). random value add together 1.

objective-c

No comments:

Post a Comment