2つの別々の(ただし並列の)配列からの画像とテキストをテーブルビューに入力する方法を探しています。私は、可能なすべてのコンテンツでインスタンス化された2つの可変配列から始め、モデルオブジェクトのコンテンツをチェックし、「空白」のエントリを削除し、残っているものをテーブルビューのセルに入力するテーブルビュープロパティにコピーしようとしています。
(初期値を取得しているオブジェクトは、渡されるモデルオブジェクトです。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
、例外がスローされます。)
コメントアウトされた行からわかるように、このメソッドをリファクタリングして、内容ではなくインデックスを追跡しようとしましたが、それではテーブルをロードすることさえできませんでした。
私はこれをすべて間違った方法で行っているようですが、より良いアプローチを思い付くことができません。何か案は?