English 中文(简体)
硬编码 第1节核心数据表
原标题:hardcoded Tablecells in section 0, core-data fetched-results in section 1

my problem ist that i have UITableView with two sections. In the first section i have objects of a NSArray and the second section should be filled with core-data results.

But if i use the fetchedResultsController it sets the section of his data to 0 and not to 1 as i need.
So cellForIndexPath uses the indexPath, and if i want to display the core-data in section 1 the fetchedResultsController doesn t find data.
My current workaround is

if (indexPath.section == 1) {
    NSIndexPath *temp = [NSIndexPath indexPathForRow:indexPath.row inSection:indexPath.section-1];

and then use temp instead of indexPath.
But it s very ugly to check in every UITableView function if the section==1.

能否在第1节中找到直接结果?

Thank you very much! Seega

最佳回答

警告:

给贵实体增加“部门预算”价值,并即刻发行该实体的模版,其价值为零,用于Kludge(主宰本目标,你在桌上看不见),然后即所有实体,价值为1(你甚至可能为这一任择财产的违约价值)。 在您的FRC中,NameKeyPath被定为“Kludge”,然后使用Rogs的答复。

I have groaned about doing what you are asking in several of the table views that I have in apps that I write... I usually just back down and manually fool with the array and not use an FRC.

我只想像你所说的那样调整国家健康倡议。

问题回答

阁下 主计长定下WHERE的数据将插入,这取决于您的表格数据。 资料来源:根据您提出的逻辑开展工作的方法。

我没有你们执行工作的所有细节,但以下几段内容大致应该做你想要达到的目标。 你们完全需要测试贵国法典某些部分的(部分)价值,以确定你将如何填写各科和行的数据。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"CellIdentifier";
    UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
    }
    if (indexPath == kSectionZero) {
          // Configure cell with data from NSArray here
    } else {
          NSManagedObject *yourObject = [self.fetchedResultsController objectAtIndexPath:indexPath];
          // Configure cell with data from *yourObject here
    }
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    NSUInteger count = [[self.fetchedResultsController sections] count];
    return count + X; // where X == number of additional sections you want, in your case X == 1
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section == 1) {
        id <NSFetchedResultsSectionInfo> sectionInfo = [[self.fetchedResultsController sections] objectAtIndex:section];
        return [sectionInfo numberOfObjects]
    } else return [arrayObject count]
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
    if (section == 1) {
        NSString *sectionName = [[[self.fetchedResultsController sections] objectAtIndex:section] name];
        return sectionName;
        } else return @"Whatever section name you want for section == 0 here";
    }
}




相关问题
Asynchronous request to the server from background thread

I ve got the problem when I tried to do asynchronous requests to server from background thread. I ve never got results of those requests. Simple example which shows the problem: @protocol ...

objective-c: Calling a void function from another controller

i have a void, like -(void) doSomething in a specific controller. i can call it in this controller via [self doSomething], but i don t know how to call this void from another .m file. I want to call ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

NSUndoManager and runModalForWindow:

I have a simple Core Data app which displays a list of entities in the main window. To create or add new entities, I use a second modal window with a separate managed object context so changes can be ...

NSMutableArray values becoming "invalid"

I m trying to show a database information in a tableview and then the detailed information in a view my problem is as follow: I created a NSMutableArray: NSMutableArray *myArray = [[NSMutableArray ...

iPhone numberpad with decimal point

I am writing an iPhone application which requires the user to enter several values that may contain a decimal point (currency values, percentages etc.). The number of decimal places in the values ...

热门标签