我正在尋找一種方法來填充表視圖與兩個單獨的(但並行)數組中的圖像和文本。我一直試圖從兩個使用所有可能的內容實例化的可變數組開始,檢查模型對象的內容,刪除「空白」條目,並將剩下的內容複製到填充表視圖單元格的表視圖屬性中。如何從兩個數組中填充表格視圖內容?
(該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