2015-01-03 85 views
-3

我已经创建了一个coreData应用,我救了我的NSString的使用添加的NSString特别UITableViewCells

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath]; 

    Person *person = [self.fetchedResultsController objectAtIndexPath:indexPath]; 
    cell.textLabel.text = [NSString stringWithFormat:@"%@",person.personType]; 

    return cell; 
} 

在一个UITableView显示他们,我想使它所以这些结果开始后10的UITableView显示细胞,并在前10个细胞中,我只是添加一个预设的NSString,将永远是相同的?任何帮助将很大

回答

0

使用if声明并检查indexPath.row

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath]; 

    if (indexPath.row < 10) { 
     cell.textLabel.text = ... // some hardcoded value for the first 10 rows 
    } else { 
     NSIndexPath *newPath = [NSIndexPath indexPathForRow:indexPath.row - 10 inSection:indexPath.section]; 
     Person *person = [self.fetchedResultsController objectAtIndexPath:newPath]; 
     cell.textLabel.text = person.personType; 
    } 

    return cell; 
} 

而且你的numberOfRowsInSection方法还需要返回10多行。

+0

In person * person = [self.fetchedResultsController objectAtIndexPath:indexPath - 10]; “-10”似乎不起作用? – burrGGG

+0

为什么不呢?请详细说明。 – rmaddy

+0

它打破了,说'不兼容的整数指向int类型的指针转​​换发送到NSIndexpath'。难道是因为numberOfRowsInSection增加了10?这就是我在numberOfRowsInSection id secInfo = [[self.fetchedResultsController sections] objectAtIndex:section]; return [secInfo numberOfObjects] + 10; – burrGGG