Objective c 如何从两个数组填充表视图内容?
我正在寻找一种用来自两个独立(但并行)数组的图像和文本填充表视图的方法。我一直在尝试从两个可变数组开始,用所有可能的内容实例化,检查模型对象的内容,删除“空白”条目,并将剩余内容复制到填充表视图单元格的表视图属性中 (从中获取其初始值的Objective c 如何从两个数组填充表视图内容?,objective-c,c,uitableview,nsmutablearray,nsarray,Objective C,C,Uitableview,Nsmutablearray,Nsarray,我正在寻找一种用来自两个独立(但并行)数组的图像和文本填充表视图的方法。我一直在尝试从两个可变数组开始,用所有可能的内容实例化,检查模型对象的内容,删除“空白”条目,并将剩余内容复制到填充表视图单元格的表视图属性中 (从中获取其初始值的person对象是传入的模型对象。) 这适用于档案列表,但不适用于按钮列表。(此后,在tableView:cellForRowAtIndexPath:中,cell.textlab.text设置良好,但cell.imageView.image引发异常。) 从注释掉的
person
对象是传入的模型对象。)
这适用于档案列表
,但不适用于按钮列表
。(此后,在tableView:cellForRowAtIndexPath:
中,cell.textlab.text
设置良好,但cell.imageView.image
引发异常。)
从注释掉的行中可以看出,我尝试重构此方法以跟踪索引而不是内容,但是使用此方法,我甚至无法加载表
看起来我做得不对,但我想不出更好的办法。有什么想法吗?好的,指针:)
- 不要使用快速枚举,而是使用普通for循环(for(inti=0;i
- 将所有索引存储在
NSMutableIndexSet
- 使用
清除所有对象,方法是在两个数组上调用它removeObjectsIndexes:
- 将所有索引存储在
编辑:或者,颠倒for循环的顺序(int=COUNT-1;i>=0;i--),直接从数组中删除对象。我应该补充:我不想让任何人为我编写解决方案,只要帮我自己找到如何修复(或以什么新的方向开始)代码。你知道,我从未知道或研究过
NSIndexSet
类或它们的用途。然而,通过数组反向工作可以完美、简洁地工作,我从来没有想到过这一点。谢谢你的帮助!
NSMutableArray *profileList = [@[person.facebook, person.twitter, person.pinterest, person.linkedIn, person.youTube, person.googlePlus, person.flickr] mutableCopy];
NSMutableArray *buttonList = [@[@"btn-Facebook.png", @"btn-Twittter.png", @"btn-Pinterest.png", @"btn-LinkedIn.png", @"btn-YouTube.png", @"btn-Google+.png", @"btn-Flickr.png"] mutableCopy];
NSMutableArray *indicesToRemove = [@[] mutableCopy];
// for (NSString *index in profileList) {
//
// }
int i = 0;
for (NSString *indexContents in profileList) {
if ([indexContents isEqual: @""]) {
// [indicesToRemove addObject:[NSString stringWithFormat:@"%d", i]];
[indicesToRemove addObject:indexContents];
}
i++;
}
for (NSString *count in indicesToRemove) {
// [profileList removeObjectAtIndex:[count integerValue]];
[profileList removeObject:count];
// [buttonList removeObjectAtIndex:[count integerValue]];
}
self.socialMediaProfilesList = (NSArray *)profileList;
self.socialMediaButtonsList = (NSArray *)buttonList;