How to increment currentindex so that textview can be updated in a sequence manner than randomly.
- (void)viewDidLoad{
myArray = [[NSMutableArray alloc]initWithObjects:@"String1",@"String2",@"String3",@"String4", @"String5",..... nil];
[NSTimer scheduledTimerWithTimeInterval:2.0
target:self
selector:@selector(updateText:)
userInfo:nil
repeats:NO];
self.textView.font = [UIFont fontWithName:@"Baskerville-Bold" size:22];
self.textView.textAlignment = NSTextAlignmentCenter;
self.textView.backgroundColor = [UIColor clearColor];
self.textView.textAlignment = NSTextAlignmentCenter;
self.textView.text = @"String1";
self.textView.scrollEnabled = NO;
self.textView.editable = NO;
self.textView.userInteractionEnabled = NO;
[baseView addSubview: self.textView];
}
- (void)updateText:(NSTimer *)theTimer {
int index = arc4random() % [myArray count];
myTextView.text = [myArray objectAtIndex:index];
}
Instead of making index a local variable, make it a property
@property (nonatomic) NSInteger index;
in viewDidLoad initialize it to 0;
Then use it like this only:
and i hope you are using Timer like this :