在UITableView中切换页面

时间:2015-03-30 10:07:07

标签: ios uitableview

我使用SWRevealViewController这个Source来制作我的应用, 但我不知道为什么我按下我的tableview单元格项目时无法切换页面, 有人帮我解决了我的问题吗?

这是我的.m文件: 我尝试鬃毛方法,但仍然没有工作......

    #import "RevealTableViewController.h"
    #import "SWRevealViewController.h"
    #import "PhotoViewController.h"

    @interface RevealTableViewController ()

    @end

    @implementation RevealTableViewController  {
        NSMutableArray *menuItems;
        NSMutableArray *detailitemlist;
    }

    - (void)viewDidLoad {
        [super viewDidLoad];

        menuItems = [[NSMutableArray alloc] init];
        [menuItems addObject:@"CART"];
        [menuItems addObject:@"WISHLIST"];

        detailitemlist = [[NSMutableArray alloc]init];
        [detailitemlist addObject:@"NEW ARRIVALS"];
        [detailitemlist addObject:@"BRANDS"];
        [detailitemlist addObject:@"CLOTHING"];

    }

    - (void)didReceiveMemoryWarning {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }

    #pragma mark - Table view data source

    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

        return 2;
    }

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

        NSInteger n = 0 ;
        switch (section) {
            case 0:
                n = [menuItems count];
                break;

            case 1:
                n = [detailitemlist count];
                break;
        }
        return n;
    }


    - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
    {
        NSString *sectionName;
        switch (section)
        {
            case 1:
                sectionName =@"   CATEGORIES";
                break;
        }
        return sectionName;
    }


    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
        if ([tableView respondsToSelector:@selector(setSeparatorInset:)]) {
            [tableView setSeparatorInset:UIEdgeInsetsZero];
        }
        if ([tableView respondsToSelector:@selector(setLayoutMargins:)]) {
            [tableView setLayoutMargins:UIEdgeInsetsZero];
        }

        static NSString *indictor = @"Cell";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:indictor];


        if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
            [cell setLayoutMargins:UIEdgeInsetsZero];
        }

        if (cell == nil){
            cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:indictor];

        }
        switch (indexPath.section) {
            case 0:
                cell.textLabel.text = [menuItems objectAtIndex:indexPath.row];
                break;

            case 1:
                cell.textLabel.text = [detailitemlist objectAtIndex:indexPath.row];
                break;
        }
        return cell;

        }
    #pragma mark - Navigation

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

    NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
    UINavigationController *destViewController = (UINavigationController*)segue.destinationViewController;
    destViewController.title = [[menuItems objectAtIndex:indexPath.row] capitalizedString];


    if ([segue.identifier isEqualToString:@"showPhoto"]) {
        UINavigationController *navController = segue.destinationViewController;
        PhotoViewController *photoController = [navController childViewControllers].firstObject;
        NSString *photoFilename = [NSString stringWithFormat:@"%@_photo", [menuItems objectAtIndex:indexPath.row]];
        photoController.photoFilename = photoFilename;
    }
}

    @end

这是我的应用图片...... enter image description here

0 个答案:

没有答案