Ios在IBMoutletCollection文本视图上迭代
我试图在文本视图集合上迭代并显示我的数组Ios在IBMoutletCollection文本视图上迭代,ios,objective-c,uitextview,iboutletcollection,Ios,Objective C,Uitextview,Iboutletcollection,我试图在文本视图集合上迭代并显示我的数组 @property(强,非原子)IBOutletCollection(UITextView)NSArray*myTextViewCollection 但在UI上,只有数组中的最后一个元素可用 我使用以下方法进行迭代: for (UITextView *textView in myTextViewCollection) { for (int i = 0; i < feeds.count; i++) { t
@property(强,非原子)IBOutletCollection(UITextView)NSArray*myTextViewCollection代码>
但在UI上,只有数组中的最后一个元素可用
我使用以下方法进行迭代:
for (UITextView *textView in myTextViewCollection) {
for (int i = 0; i < feeds.count; i++) {
textView.text = [[feeds objectAtIndex:i] objectForKey:@"title"];
textView.editable = false;
}
}
for(myTextViewCollection中的UITextView*textView){
for(int i=0;i
提要
是一个包含NSMutableDictionary对象列表的NSMutableArray
想法?试试这个:
int i = 0;
for (UITextView *textView in myTextViewCollection) {
textView.text = [[feeds objectAtIndex:i++] objectForKey:@"title"];
textView.editable = false;
}
应该是这样的:
for (int i = 0; i < myTextViewCollection.count; i++) {
UITextView * textView = myTextViewCollection[i];
textView.text = [[feeds objectAtIndex:i] objectForKey:@"title"];
textView.editable = false;
}
for(int i=0;i
您的代码
for (UITextView *textView in myTextViewCollection) {
for (int i = 0; i < feeds.count; i++) {
textView.text = [[feeds objectAtIndex:i] objectForKey:@"title"];
textView.editable = false;
}
}
这就是为什么只显示最后一个元素数组的原因
您应该将代码更改为
int i = 0;
for (UITextView *textView in myTextViewCollection) {
textView.text = feeds[i++][@"title"];
textView.editable = false;
}
“i”变量来自何处?我已编辑我的问题以添加i变量。我已测试,此操作仅显示我数组的一个元素。是否记录“feed”以确保其包含正确的值?如果feed和myTextViewCollection都设置正确,则此操作应能正常工作。到目前为止提交的每个答案在解决您最初的问题时都是正确的。如果仍然存在错误,则是其他错误。好的,问题可能与myTextViewCollection有关?如何初始化它?for循环只需执行一次迭代您是否在调试器中使用断点单步执行代码?我也测试了此解决方案。。。但结果与初始上下文相同
int i = 0;
for (UITextView *textView in myTextViewCollection) {
textView.text = feeds[i++][@"title"];
textView.editable = false;
}