每个数据在表视图中打开自己的nib文件

时间:2011-04-05 16:10:09

标签: objective-c xcode uitableview

嘿伙计们, 我有一个正确排序的表视图,但我有一个问题,我的表视图上的每个数据在我使用此代码时打开同一个nib文件:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
        // Return the number of sections.
        return 4;
}

// Category
- (NSString *)tableView:(UITableView *)tableView 
titleForHeaderInSection:(NSInteger)section {
        if (section == 0) return @"In-Site SEO";
        if (section == 1) return @"Inside Analysis";
        if (section == 2) return @"Ranks N Stuff";
        if (section == 3) return @"Server Info";
        return @"Other";
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
        // Return the number of rows in the section.
        if (section == 0) return 7;
        if (section == 1) return 3;
        if (section == 2) return 6;
        if (section == 3) return 5;
        return 0;
}

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
        static NSString *CellIdentifier = @"Cell";

        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
                cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
        }

        // Configure the cell...
        NSUInteger row = [indexPath row];
        if ( indexPath.section == 1 ) row += 7;
        if ( indexPath.section == 2 ) row += 10;
        if ( indexPath.section == 3 ) row += 16;
        if ( indexPath.section == 4 ) row += 21;
        cell.textLabel.text = [glossaryArray objectAtIndex:row];

        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

        return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
        NSInteger row = [indexPath row];
        if (self.glossaryDetailViewController == nil) {
                GlossaryDetailViewController *aGlossaryDetail = [[GlossaryDetailViewController alloc] initWithNibName:@"GlossaryDetailViewController" bundle:nil];
                self.glossaryDetailViewController = aGlossaryDetail;
                [aGlossaryDetail release];
        }
        glossaryDetailViewController.title = [NSString stringWithFormat:@"%@", [glossaryArray objectAtIndex:row]];

        NewReferencemoi_caAppDelegate *delegate = (NewReferencemoi_caAppDelegate *)[[UIApplication sharedApplication] delegate];
        [delegate.glossaryNavController pushViewController:glossaryDetailViewController animated:YES];
}
  • GlossaryDetailViewController是我的实现文件,我也添加了nib文件,

所以希望有人可以帮助我如何让每个数据打开他们自己的视图,我不会介意我是否必须为我的表视图中的每个和所有数据创建一个nib文件,

感谢

1 个答案:

答案 0 :(得分:0)

要输入您的代码样式,您可以尝试

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
        NSInteger row = [indexPath row];
        NSString *nibName;

        if ( indexPath.section == 1 ) nibName = @"firstNib";
        if ( indexPath.section == 2 ) nibName = @"secondNib";
        if ( indexPath.section == 3 ) nibName = @"thirdNib";
        if ( indexPath.section == 4 ) nibName = @"fourthNib";

        GlossaryDetailViewController *aGlossaryDetail = [[GlossaryDetailViewController alloc] initWithNibName:nibName bundle:nil];
        self.glossaryDetailViewController = aGlossaryDetail;
        [aGlossaryDetail release];

        glossaryDetailViewController.title = [NSString stringWithFormat:@"%@", [glossaryArray objectAtIndex:row]];

        NewReferencemoi_caAppDelegate *delegate = (NewReferencemoi_caAppDelegate *)[[UIApplication sharedApplication] delegate];
        [delegate.glossaryNavController pushViewController:glossaryDetailViewController animated:YES];
}