2012-07-06 104 views
0

我需要在索引路径的cellForRow的tableview中实现两个不同的索引路径...一个来自我提取的结果控制器的数据,另一个来自简单文本。多索引路径

什么是最好的方式去做这件事。

回答

0

我不完全确定你的问题,但它听起来像你想要一个表,其中一节包含NSFetchedResultController的结果,另一节包含来自其他源的数据。这很容易做到。如果您的数据可以不需要在多个部分,然后它很容易,只要得到fetchedResultController为第0,和别的数据为第1

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ 
    return 2; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ 
    if(section == 0){  
     id sectionInfo = [[fetchedResultsController sections] objectAtIndex:section]; 
     return [sectionInfo numberOfObjects]; 
    }else{ 
     return self.someArray.Count; 
    } 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 
    if(indexpath.section == 0){  
      static NSString *CellIdentifier = @"data cell"; 
      UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
      NSObject *foo = [self.fetchedResultController objectAtIndexPath:indexPath]; 
      //configure cell 
      return cell; 
     }else{ 
      static NSString *CellIdentifier = @"some other cell"; 
      UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

      //configure cell 
      return cell; 
    } 
} 
+0

谢谢你,这就是我一直在寻找。 – Luke 2012-07-07 21:13:30