Should be like this:
for (int i = 0; i < myTextViewCollection.count; i++) {
UITextView * textView = myTextViewCollection[i];
textView.text = [[feeds objectAtIndex:i] objectForKey:@"title"];
textView.editable = false;
}
Question
I'm trying to iterate and show my array on my text view collection.
@property (strong, nonatomic) IBOutletCollection(UITextView) NSArray *myTextViewCollection;
But on the UI, only the last element in my array is available.
I iterate with :
for (UITextView *textView in myTextViewCollection) {
for (int i = 0; i < feeds.count; i++) {
textView.text = [[feeds objectAtIndex:i] objectForKey:@"title"];
textView.editable = false;
}
}
feeds
is a NSMutableArray contening a list of NSMutableDictionnary object.
An idea ?
Solution
Should be like this:
for (int i = 0; i < myTextViewCollection.count; i++) {
UITextView * textView = myTextViewCollection[i];
textView.text = [[feeds objectAtIndex:i] objectForKey:@"title"];
textView.editable = false;
}
OTHER TIPS
Try this:
int i = 0;
for (UITextView *textView in myTextViewCollection) {
textView.text = [[feeds objectAtIndex:i++] objectForKey:@"title"];
textView.editable = false;
}
Your code
for (UITextView *textView in myTextViewCollection) {
for (int i = 0; i < feeds.count; i++) {
textView.text = [[feeds objectAtIndex:i] objectForKey:@"title"];
textView.editable = false;
}
}
is equivalent to
for (UITextView *textView in myTextViewCollection) {
textView.text = [[feeds objectAtIndex:feeds.count - 1] objectForKey:@"title"];
textView.editable = false;
}
this is the reason why only the last element array is shown.
You should change code to something like
int i = 0;
for (UITextView *textView in myTextViewCollection) {
textView.text = feeds[i++][@"title"];
textView.editable = false;
}