UITableView segue无法正常工作

nev*_*asy 2 uitableview ios segue

我在文档中关注了SimpleDrillDown应用程序示例,该应用程序在第一个UITableView中显示锻炼名称,在第二个UITableView中显示锻炼.

我的应用程序在Dropbox这里:http://db.tt/V0EhVcAG

我使用了故事板,有原型单元格,但是当我在模拟器中加载时,第一个UITableView不会让我点击并转到细节UITableView.披露指标V形不加载.该应用程序构建成功,没有正式错误.

我的表视图位于导航控制器中,我的segue和prototype单元都在故事板中相应命名.

SpitfireViewController.m

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [dataController countOfList];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"WorkoutCell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

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

    Workout *workoutAtIndex = [dataController objectInListAtIndex:indexPath.row];
    cell.textLabel.text = workoutAtIndex.title;

    return cell;
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:@"showExercises"]) {
        NSIndexPath *selectedRowIndex = [self.tableView indexPathForSelectedRow];

        DetailViewController *detailViewController = [segue destinationViewController];

        detailViewController.workout = [dataController objectInListAtIndex:selectedRowIndex.row];
    }
}
Run Code Online (Sandbox Code Playgroud)

DetailViewController.m

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

    return [workout.exercises count];
}

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

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

    cell.textLabel.text = [workout.exercises objectAtIndex:indexPath.row];
    return cell;
}
Run Code Online (Sandbox Code Playgroud)

AppDelegate.h

#import <UIKit/UIKit.h>
@class DataController;
@class SpitfireViewController;

@interface SpitfireAppDelegate : UIResponder <UIApplicationDelegate>
{
    UIWindow *window;
    SpitfireViewController *spitfireViewController;
    DataController *dataController;
}

@property (strong, nonatomic) UIWindow *window;

@end
Run Code Online (Sandbox Code Playgroud)

AppDelegate.m

#import "SpitfireAppDelegate.h"
#import "SpitfireViewController.h"
#import "DataController.h"

@implementation SpitfireAppDelegate
@synthesize window;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

    spitfireViewController = [[SpitfireViewController alloc] init];
    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:spitfireViewController];

    DataController *controller = [[DataController alloc] init];
    spitfireViewController.dataController = controller;

    [window addSubview:[navController view]];
    [self.window makeKeyAndVisible];

    return YES;
}

@end
Run Code Online (Sandbox Code Playgroud)

我的故事板 SpitfireViewController(Root) DetailViewController

小智 5

如果你有tableview cell segue selection问题.

已启用选择的Tableview

  • 您需要先检查您的tableview是否允许选择
  • 你不需要实现UITableViewDelegateUITableViewDataSource使用"静态单元格"
  • 您需要为附件操作添加segue +为选择添加segue.

一个segue用于表视图选择另一个用于附件动作