ios - UILabel wont show the previous characters, only the last letter -


Each character in the target string is to be enumerated, it will appear as 'W', after which 'h' changes after 1 second Will be given, then 'E' and 'N'. The problem my label only displays the last letter

What did I do? 1. Drag a label and a button on PlayViewController. 2. Create an asset for the label 3. Take action for the button

In my PlayViewController.h:

  #import & lt; UIKit / UIKit.h & gt; @ Interface playview controller: UIViewController @property (strong, nonatomic) IBOutlet UILabel * listChar; - (IBAction) Initiation: (ID) Sender; @end  

In my PlayViewController.m:

  #import "PlayViewController.h" @interface PlayViewController () @end @implementation PlayViewController NSString * word; NSTimer * myTimer; - (zero) viewDidoadload [[Super Viewedload]; // Setup an additional after loading the view self.listChar.text = @ ""; Word = "when"; } - (IBAction) startGame: (ID) sender {myTimer = [NSTimer scheduled timer with time interval: 1.0 target: auto selector: @selector (listLetter :) userInfo: zero repeats: yes]; } - (zero) list letter: (NSTimer *) myTimer {for (int i = 0; i & lt; [word length]; i ++) {unichar letter = [word characterAtIndex: i]; Self.listChar.text = [NSString stringWithFormat: @ "% C", letter]; }} @end  
"post-text" itemprop = "text">

If you want to know why this is happening then @ Nitin Answer, and if you want to solve in other ways, then only use the following code

  - (zero) listLetter: (NSTimer *) myTimer static int pos = 1; Self.listChar.text = [word substringToIndex: pos]; If (++ pos> word.length) {[myTimer invalid]; }}  

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -