开发者

Each data opening their own nib files in Table View

Hey guys, I have a Table View sorted out properly, but I have a problem, each data on my Table View is opening the one and same nib file when I'm using this code:

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

// Category
- (NSString *)tableView:(UITableView *)tableView 
titleForHeaderInSection:(NSInteger)section {
        if (section == 0) return @开发者_StackOverflow"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 is my implementation file and also I added the nib file for that,

So hopefully someone can help me how to have each data open their own view, I won't really mind if I have to make a nib file for each and all my data on my Table View,

thanks


To put in your code style you can try

- (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];
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜