我正在寻找一种方法来填充表视图与两个单独的(但并行)数组中的图像和文本。我一直试图从两个使用所有可能的内容实例化的可变数组开始,检查模型对象的内容,删除“空白”条目,并将剩下的内容复制到填充表视图单元格的表视图属性中。如何从两个数组中填充表格视图内容?
(该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
抛出异常。)
正如你或许可以从注释掉的线条诉说,我试图重构这个方法来跟踪指数,而不是内容,而是与我甚至无法加载表格。
看来我似乎正在全力以赴,但我无法想出更好的方法。有任何想法吗?
我应该补充一点:我不是在寻找任何人为我编写解决方案,只是帮助我找到如何解决(或开始自己的新方向)代码。 – ele 2013-03-05 22:43:10