我有一个基于标签的应用程序。在第一个选项卡上,我有几个视图,其中一个是导航控制器。我的目标是加载此列表视图(工作),然后在单元格单击时转到详细视图(不工作)。
在单元格上单击我正在记录
NSLog(@"%@",self.navigationController);
这是返回一个空值。我只能假设我没有正确设置导航控制器,但我不知道是什么。
在按钮上单击表视图被称为:
#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
西布照片:
.h 文件:
#import <UIKit/UIKit.h>
#import "XMLParser.h"
#import "Review_Object.h"
@interface Reviews : UIViewController
@property (retain, nonatomic) IBOutlet UITableView *reviewsTableView;
@end