显示Null的UI导航控制器为切换到细节视图

时间:2012-06-11 18:16:38

标签: iphone ios

我有一个基于标签的应用程序。在第一个选项卡上,我有几个视图,其中一个是导航控制器。我的目标是加载此列表视图(工作),然后在单元格单击(不工作)上转到详细视图。

在单元格上单击我正在记录

  

的NSLog(@ “%@”,self.navigationController);

返回null。我只能假设我没有正确设置导航控制器,但我不知道是什么。

单击按钮上的

,将调用表视图:

#import "Reviews.h"
#import "XMLParser.h"
#import "Detailed_Review.h"

@implementation Reviews

@synthesize reviewsTableView;

XMLParser *xmlParser;
CGRect dateFrame;
UILabel *dateLabel;
CGRect contentFrame;
UILabel *contentLabel;

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark -
#pragma mark Table view data source

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

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{
    return [[xmlParser reviews] count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{

    static NSString *CellIdentifier = @"Cell";
Review_Object *currentReview = [[xmlParser reviews] objectAtIndex:indexPath.row];

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

        CGRect contentFrame = CGRectMake(10, 2, 265, 30);
        UILabel *contentLabel = [[UILabel alloc] initWithFrame:contentFrame];
        contentLabel.tag = 0011;
        contentLabel.numberOfLines = 2;
        contentLabel.font = [UIFont boldSystemFontOfSize:12];
        [cell.contentView addSubview:contentLabel];

        CGRect reviewFrame = CGRectMake(10, 40, 265, 10);
        UILabel *reviewLabel = [[UILabel alloc] initWithFrame:reviewFrame];
        reviewLabel.tag = 0012;
        reviewLabel.font = [UIFont systemFontOfSize:10];
        [cell.contentView addSubview:reviewLabel];
    }

UILabel *contentLabel = (UILabel *)[cell.contentView viewWithTag:0011];
    contentLabel.text = [currentReview rating];

UILabel *dateLabel = (UILabel *)[cell.contentView viewWithTag:0012];
    dateLabel.text = [currentReview review];

    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 55;
}

#pragma mark -
#pragma mark Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{
     Detailed_Review *dvController = [[Detailed_Review alloc] initWithNibName:@"Detailed_Review" bundle:[NSBundle mainBundle]];

    [self.navigationController pushViewController:dvController animated:YES];
    NSLog(@"%@",self.navigationController);
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];

    xmlParser = [[XMLParser alloc] loadXMLByURL:@"http://www.mywebsite.com/api/reviews/xml.php?page=1"];

    self.title = @"Reviews";
}

- (void)viewDidUnload
{
    [self setReviewsTableView:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
}

- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

@end

xib照片:

first tab.xim

devtailview.xib

.h文件:

#import <UIKit/UIKit.h>
#import "XMLParser.h"
#import "Review_Object.h"

@interface Reviews : UIViewController

@property (retain, nonatomic) IBOutlet UITableView *reviewsTableView;

@end

1 个答案:

答案 0 :(得分:0)

您省略了分配和初始化navigationController的部分。你可以添加它,包括.h文件中的相关部分吗?

使用IB或以编程方式创建它,请参阅https://developer.apple.com/library/ios/#documentation/WindowsViews/Conceptual/ViewControllerPGforiOSLegacy/NavigationControllers/NavigationControllers.html#//apple_ref/doc/uid/TP40011381-CH103-SW27