我有一个非常具体的问题。我是Xcode的新手,但到目前为止,我能够使用标签栏控制器创建一个应用程序,其中一个标签控制器是tableviewcontroller。我在tableviewcontroller中显示表格单元格没有问题,甚至点击其中的任何一个都是segueing到detailviewcontroller,其中表格单元格有广泛的信息,但我的问题是当我试图通过点击菜单按钮,我想要一个标签时更进一步以及要显示的菜单图像。我得到一个空白的屏幕。我甚至看不到标题,甚至没有谈论推动图像。 我认为问题在于通过一个级别推送信息。 这是TableViewController.h:
#import <UIKit/UIKit.h>
@interface TableViewController1 : UITableViewController
@property (nonatomic, strong) NSArray *Menus;
@property (nonatomic, strong) NSArray *Images;
@property (nonatomic, strong) NSArray *Title;
@property (nonatomic, strong) NSArray *Description;
@end
和TableViewController.m:
#import "TableViewController1.h"
#import "TableCell1.h"
#import "DetailViewController.h"
#import "MenuViewController.h"
@interface TableViewController1 ()
@end
@implementation TableViewController1
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
self.tableView.separatorColor = [UIColor colorWithRed:0/255.0 green:181/255.0 blue:0/255.0 alpha:0.5];
UIBarButtonItem *NewBackButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStyleBordered target:nil action:nil];
[[self navigationItem] setBackBarButtonItem:NewBackButton];
_Title = @[@"Velvet Sport Villa",
@"GQ",
@"29",
@"Noodles",
@"La Roof",
@"Borgo Antico",
@"Vertalet",
@"Balcon",
@"Parmigiano",];
_Description = @[@"The New Great Place",
@"Want to feel some luxury",
@"The Old Good Place",
@"Food is amazing here",
@"Too expensive",
@"Royal place",
@"Before party or After party",
@"Great place, great deserts",
@"The first place in town of that level",];
_Images = @[@"Velvet.jpg",
@"GQ.jpg",
@"29.jpg",
@"Noodles.jpg",
@"La Roof.jpg",
@"Borgo Antico.jpg",
@"Vertalet.jpg",
@"Balcon.jpg",
@"Parmigiano.jpg",];
_Menus = @[@"Velvet Menu.jpg",
@"GQ Menu.jpg",
@"29 Menu.jpg",
@"Noodles Menu.jpg",
@"La Roof Menu.jpg",
@"Borgo Antico Menu.jpg",
@"Vertalet Menu.jpg",
@"Balcon Menu.jpg",
@"Parmigiano Menu.jpg",];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return _Title.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"TableCell1";
TableCell1 *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
// Configure the cell...
int row = [indexPath row];
cell.TitleLabel.text = _Title[row];
cell.DescriptionLabel.text = _Description[row];
cell.ThumbImage.image = [UIImage imageNamed:_Images[row]];
return cell;
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"ShowDetails"])
{
DetailViewController *detailviewcontroller = [segue destinationViewController];
NSIndexPath *myInderPath = [self.tableView indexPathForSelectedRow];
int row = [myInderPath row];
detailviewcontroller.DetailModal = @[_Title[row],_Description[row],_Images[row],_Menus[row]];
}
if ([[segue identifier] isEqualToString:@"MenuDetails"])
{
MenuViewController *menuviewcontroller = [segue destinationViewController];
NSIndexPath *myInderPath = [self.tableView indexPathForSelectedRow];
int row = [myInderPath row];
menuviewcontroller.MenuModal = @[_Title[row],_Menus[row]];
}
}
@end
TableCell1.h
#import <UIKit/UIKit.h>
@interface TableCell1 : UITableViewCell
@property(strong,nonatomic) IBOutlet UILabel *TitleLabel;
@property(strong,nonatomic) IBOutlet UILabel *DescriptionLabel;
@property(strong,nonatomic) IBOutlet UIImageView *ThumbImage;
@end
TableCell1.m
#import "TableCell1.h"
@implementation TableCell1
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
}
return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
@end
DetailViewController.h
#import <UIKit/UIKit.h>
@interface DetailViewController : UIViewController
@property (weak, nonatomic) IBOutlet UILabel *Cuisine;
@property (weak, nonatomic) IBOutlet UILabel *Price;
@property (weak, nonatomic) IBOutlet UILabel *Decor;
@property (weak, nonatomic) IBOutlet UILabel *Service;
@property(strong,nonatomic) IBOutlet UILabel *TitleLabel;
@property(strong,nonatomic) IBOutlet UILabel *DescriptionLabel;
@property(strong,nonatomic) IBOutlet UIImageView *ThumbImage;
@property(strong,nonatomic) NSArray *DetailModal;
@end
DetailViewController.m
#import "DetailViewController.h"
@interface DetailViewController ()
@end
@implementation DetailViewController
- (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.
_TitleLabel.text = _DetailModal[0];
_DescriptionLabel.text = _DetailModal[1];
_ThumbImage.image = [UIImage imageNamed:_DetailModal[2]];
self.navigationItem.title = _DetailModal[0];
if ([_TitleLabel.text isEqualToString:@"Velvet Sport Villa"])
{
_Cuisine.text = @"German/American";
_Price.text = @"Above average";
_Decor.text = @"Great. Sporty, but cozy";
_Service.text = @"Exceptional";
}
if ([_TitleLabel.text isEqualToString:@"GQ"])
{
_Cuisine.text = @"Italian/English";
_Price.text = @"Above average";
_Decor.text = @"Exceptional";
_Service.text = @"Average";
}
if ([_TitleLabel.text isEqualToString:@"29"])
{
_Cuisine.text = @"Japanese/Italian";
_Price.text = @"Average";
_Decor.text = @"Cozy";
_Service.text = @"So So";
}
if ([_TitleLabel.text isEqualToString:@"Noodles"])
{
_Cuisine.text = @"Chinese/Italian";
_Price.text = @"Average";
_Decor.text = @"Interesting";
_Service.text = @"Groomy, but fast";
}
if ([_TitleLabel.text isEqualToString:@"La Roof"])
{
_Cuisine.text = @"American/Italian";
_Price.text = @"Very High";
_Decor.text = @"OK";
_Service.text = @"OK";
}
if ([_TitleLabel.text isEqualToString:@"Borgo Antico"])
{
_Cuisine.text = @"Medeterranean";
_Price.text = @"Above average";
_Decor.text = @"Marvelous";
_Service.text = @"Not Bad";
}
if ([_TitleLabel.text isEqualToString:@"Vertalet"])
{
_Cuisine.text = @"All";
_Price.text = @"Above average";
_Decor.text = @"Fine, nothing special";
_Service.text = @"Not Bad";
}
if ([_TitleLabel.text isEqualToString:@"Balcon"])
{
_Cuisine.text = @"Italian/Coffee";
_Price.text = @"Above Average";
_Decor.text = @"Modern";
_Service.text = @"Best";
}
if ([_TitleLabel.text isEqualToString:@"Parmigiano"])
{
_Cuisine.text = @"Italian";
_Price.text = @"Above Average";
_Decor.text = @"Stunning";
_Service.text = @"Annoying";
}
}
@end
最后是MenuViewController.h
#import <UIKit/UIKit.h>
@interface MenuViewController : UIViewController
@property(strong,nonatomic) IBOutlet UILabel *TitleLabel;
@property (strong,nonatomic) IBOutlet UIImageView *MenuImage;
@property(strong,nonatomic) NSArray *MenuModal;
@end
最后是MenuViewController.m
#import "MenuViewController.h"
@interface MenuViewController ()
@end
@implementation MenuViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationItem.title = _MenuModal[0];
_TitleLabel.text = _MenuModal[0];
_MenuImage.image = [UIImage imageNamed:_MenuModal[3]];
}
@end