从ViewController中的Table View推送

时间:2014-01-18 17:43:05

标签: objective-c uiviewcontroller tableview navigationcontroller

我第一次做xcode项目,第一次在stackoverflow上发帖,所以请理解我对所有内容的知识水平〜

所以之前创建了一个ViewController,我决定在该ViewController中添加一个表视图,而不是使用TableViewController。我有一个嵌入了导航控制器。在表格视图中,我添加了一个表格单元格,并选择了segue push连接到我想在点击动态单元格后指向的下一个ViewController。

但问题是当我轻拍电池时,什么也没发生。

我尝试阅读其他帖子,但是对于像我这样的初学者来说,他们的谈话很难理解。

阅读其他帖子后的一些信息, 我没有编辑任何AppDelegate .h,.m

我的导航控制器没有课程。

我的主视图控制器如下:

FightersViewController.h

#import <UIKit/UIKit.h>

@interface FightersViewController : UIViewController

@property (strong, nonatomic) UIButton *menuBtn;
@property (nonatomic, strong) NSMutableArray *objects;
@property (nonatomic, strong) NSMutableArray *results;
@property (strong, nonatomic) IBOutlet UITableView *tableView;

@end

FightersViewController.m

#import "FightersViewController.h"
#import "ECSlidingViewController.h"
#import "MenuViewController.h"
#import "FighterDetailViewController.h"

@interface FightersViewController ()

@end

@implementation FightersViewController

@synthesize menuBtn;
@synthesize tableView = _tableView;

-(NSMutableArray *)objects
{
    if (!_objects)
    {
        _objects = [[NSMutableArray alloc] init];
    }
    return _objects;
}
-(NSMutableArray *)results
{
    if (!_results)
    {
        _results = [[NSMutableArray alloc] init];
    }
    return _results;
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    self.view.layer.shadowOpacity = 0.75f;
    self.view.layer.shadowRadius = 10.0f;
    self.view.layer.shadowColor = [UIColor blackColor].CGColor;

    if(![self.slidingViewController.underLeftViewController isKindOfClass:[MenuViewController class]]) {
        self.slidingViewController.underLeftViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"Menu"];
    }

    [self.view addGestureRecognizer:self.slidingViewController.panGesture];
    self.menuBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    menuBtn.frame = CGRectMake(8,10,34,24);
    [menuBtn setBackgroundImage:[UIImage imageNamed:@"menuButton.png"] forState:UIControlStateNormal];
    [menuBtn addTarget:self action:@selector(revealMenu:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.menuBtn];

    [self.objects addObject:@"John"];
    [self.objects addObject:@"Paul"];
    [self.objects addObject:@"George"];
    [self.objects addObject:@"Ringo"];

}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.objects.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = nil;

    cell = [tableView dequeueReusableCellWithIdentifier:@"MyCell"];

    if (cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"MyCell"];
    }

    cell.selectionStyle = UITableViewCellSelectionStyleGray;
    cell.accessoryType  = UITableViewCellAccessoryDisclosureIndicator;
    cell.textLabel.font = [UIFont fontWithName:@"sofachrome" size:14];
    cell.textLabel.text = self.objects[indexPath.row];

    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

}

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

- (IBAction)revealMenu:(id)sender
{
    [self.slidingViewController anchorTopViewTo:ECRight];
}

- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:@"showDetail"])
    {
        NSString *object = nil;
        NSIndexPath *indexPath = nil;

        indexPath = [self.tableView indexPathForSelectedRow];
        object = self.objects[indexPath.row];

        [[segue destinationViewController] setDetailLabelContents:object];
    }
}

@end

我已阅读其他帖子:

WebSMSDetailViewController *detailViewController = [[WebSMSDetailViewController alloc] initWithNibName:@"WebSMSDetailViewController" bundle:nil];

[self.navigationController pushViewController:detailViewController animated:YES];

还有:

UINavigationController *nc = self.navigationController;

我试过但要么没有差异,要么我得到错误,因为我不明白要替换什么

感谢您花时间阅读我的问题,我希望你们可以帮助我,因为这是我的最后一年项目,我的任务是不知道XCode。

非常感谢任何帮助!提前谢谢你们!

0 个答案:

没有答案