我正在寻找一种方法来填充表视图,其中包含来自两个独立(但并行)数组的图像和文本。我一直在尝试使用所有可能的内容实例化两个可变数组,检查模型对象的内容,删除“空白”条目,并将剩下的内容复制到填充表视图单元格的表视图属性中。 / p>
(person
获取其初始值的profileList
对象是传入的模型对象。)
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;
这适用于profileList
但不适用于buttonList
。 (从以后开始,在tableView:cellForRowAtIndexPath:
中,cell.textLabel.text
设置正常但cell.imageView.image
会引发异常。)
正如你可以从注释掉的行中看到的那样,我尝试重构这个方法来跟踪索引而不是内容,但是我甚至无法让表加载。
似乎我正在以错误的方式解决这个问题,但我无法想出更好的方法。有什么想法吗?
答案 0 :(得分:1)
好的,指针:)
NSMutableIndexSet
removeObjectsAtIndexes:
清除所有对象,方法是在两个阵列上调用它们编辑:或者,反转for循环的顺序(int = COUNT-1; i> = 0; i--)并直接从数组中删除对象。