2013-03-05 76 views
0

我正在寻找一种方法来填充表视图与两个单独的(但并行)数组中的图像和文本。我一直试图从两个使用所有可能的内容实例化的可变数组开始,检查模型对象的内容,删除“空白”条目,并将剩下的内容复制到填充表视图单元格的表视图属性中。如何从两个数组中填充表格视图内容?

(该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

我应该补充一点:我不是在寻找任何人为我编写解决方案,只是帮助我找到如何解决(或开始自己的新方向)代码。 – ele 2013-03-05 22:43:10

回答

1

好的,指针:)

  • 而不是使用快速枚举,使用普通的for循环(对于(INT I = 0;我< COUNT;我++))
  • 商店的所有索引中一个NSMutableIndexSet
  • 使用removeObjectsAtIndexes:来清除所有对象,通过调用它两个阵列上

编辑:或者,替代ly,颠倒for-loop的顺序(int = COUNT-1; i> = 0;我 - )并直接从阵列中删除对象。

+0

你知道吗,我从来不知道或看着'NSIndexSet'类或它们的用途。但是,通过数组反向工作是完美的,简洁的,我从来没有想到它。谢谢您的帮助! – ele 2013-03-06 15:46:23