Не могу заставить кнопку раскрытия / перейти к работе
Кажется, что моя работа не работает и не выскочит кнопку раскрытия:
MADViewController.h
#import <UIKit/UIKit.h>
@interface MADViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) IBOutlet UITableView *tableView;
@end
MADViewController.m
#import "MADViewController.h"
#import "PokeDetailViewController.h"
#import "Pokemonobj.h"
@interface MADViewController ()
@end
@implementation MADViewController {
NSArray *pokemons;
}
@synthesize tableView = _tableView;
- (void)viewDidLoad
{
[super viewDidLoad];
// Initialize table data
// recipes = [NSArray arrayWithObjects:@"Egg Benedict", @"Mushroom Risotto", @"Full Breakfast", @"Hamburger", @"Ham and Egg Sandwich", @"Creme Brelee", @"White Chocolate Donut", @"Starbucks Coffee", @"Vegetable Curry", @"Instant Noodle with Egg", @"Noodle with BBQ Pork", @"Japanese Noodle with Pork", @"Green Tea", @"Thai Shrimp Cake", @"Angry Birds Cake", @"Ham and Cheese Panini", nil];
Pokemonobj *poke1 = [Pokemonobj new];
poke1.name = @"Egg Benedict";
poke1.prepTime = @"30 min";
poke1.imageFile = @"egg_benedict.jpg";
poke1.ingredients = [NSArray arrayWithObjects:@"2 fresh English muffins", @"4 eggs", @"4 rashers of back bacon", @"2 egg yolks", @"1 tbsp of lemon juice", @"125 g of butter", @"salt and pepper", nil];
Pokemonobj *poke2 = [Pokemonobj new];
poke2.name = @"Mushroom Risotto";
poke2.prepTime = @"30 min";
poke2.imageFile = @"mushroom_risotto.jpg";
poke2.ingredients = [NSArray arrayWithObjects:@"1 tbsp dried porcini mushrooms", @"2 tbsp olive oil", @"1 onion, chopped", @"2 garlic cloves", @"350g/12oz arborio rice", @"1.2 litres/2 pints hot vegetable stock", @"salt and pepper", @"25g/1oz butter", nil];
Pokemonobj *poke3 = [Pokemonobj new];
poke3.name = @"Full Breakfast";
poke3.prepTime = @"20 min";
poke3.imageFile = @"full_breakfast.jpg";
poke3.ingredients = [NSArray arrayWithObjects:@"2 sausages", @"100 grams of mushrooms", @"2 rashers of bacon", @"2 eggs", @"150 grams of baked beans", @"Vegetable oil", nil];
pokemons = [NSArray arrayWithObjects:poke1, poke2, poke3, nil];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [pokemons count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"pokeCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
Pokemonobj *pokemon = [pokemons objectAtIndex:indexPath.row];
cell.textLabel.text = pokemon.name;
return cell;
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"showPokeDetail"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
PokeDetailViewController *destViewController = segue.destinationViewController;
destViewController.pokemon = [pokemons objectAtIndex:indexPath.row];
// Hide bottom tab bar in the detail view
// destViewController.hidesBottomBarWhenPushed = YES;
}
}
@end
PokeDetailViewController.h
#import <UIKit/UIKit.h>
#import "Pokemonobj.h"
@interface PokeDetailViewController : UIViewController
@property (weak, nonatomic) IBOutlet UIImageView *recipePhoto;
@property (weak, nonatomic) IBOutlet UILabel *prepTimeLabel;
@property (weak, nonatomic) IBOutlet UITextView *ingredientTextView;
@property (nonatomic, strong) Pokemonobj *pokemon;
@end
PokeDetailViewController.m
#import "PokeDetailViewController.h"
@interface PokeDetailViewController ()
@end
@implementation PokeDetailViewController
@synthesize recipePhoto;
@synthesize prepTimeLabel;
@synthesize ingredientTextView;
@synthesize pokemon;
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = pokemon.name;
self.prepTimeLabel.text = pokemon.prepTime;
self.recipePhoto.image = [UIImage imageNamed:pokemon.imageFile];
NSMutableString *ingredientText = [NSMutableString string];
for (NSString* ingredient in pokemon.ingredients) {
[ingredientText appendFormat:@"%@\n", ingredient];
}
self.ingredientTextView.text = ingredientText;
}
- (void)viewDidUnload
{
[self setRecipePhoto:nil];
[self setPrepTimeLabel:nil];
[self setIngredientTextView:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end
Pokemonobj.h
#import <Foundation/Foundation.h>
@interface Pokemonobj : NSObject
@property (nonatomic, strong) NSString *name; // name of recipe
@property (nonatomic, strong) NSString *prepTime; // preparation time
@property (nonatomic, strong) NSString *imageFile; // image filename of recipe
@property (nonatomic, strong) NSArray *ingredients; // ingredients
@end
Pokemonobj.m
#import "Pokemonobj.h"
@implementation Pokemonobj
@synthesize name;
@synthesize prepTime;
@synthesize imageFile;
@synthesize ingredients;
@end
GameViewController.h
#import <UIKit/UIKit.h>
@interface GameViewController : UIViewController
@property (nonatomic, strong) IBOutlet UIWebView *webView;
@end
GameViewController.m
#import "GameViewController.h"
@interface GameViewController ()
@end
@implementation GameViewController
@synthesize webView;
- (void)viewDidLoad
{
[super viewDidLoad];
// Add code to load web content in UIWebView
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:@"about.html" ofType:nil]];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end
Я не уверен, если вам нужно увидеть другие области кода. Но вот фрагмент пока.
2 ответа
Вы уверены, что вы установили соединение из своей ячейки с PokeDetailViewController в раскадровке, и вы установили идентификатор сегмента для PokeDetailViewController (@"showPokeDetail")? Если не добавить:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self performSegueWithIdentifier:@"showPokeDetail" sender:nil];
}
// Не забудьте установить идентификатор сегмента из вашего ViewController (не из ячейки) в PokeDetailViewController (@"showPokeDetail"),
Вам нужно установить cell.accessoryType
Попробуй сделать
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"pokeCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
Pokemonobj *pokemon = [pokemons objectAtIndex:indexPath.row];
cell.textLabel.text = pokemon.name;
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
return cell;
}
после этого вы можете реализовать
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath;
Настройте переход с @"showPokeDetail"
идентификатор в раскадровке. и вызвать переход в вышеупомянутой реализации.
[self performSegueWithIdentifier:@"showPokeDetail" sender:nil];
Примечание: когда вы используете accessoryType
вы не получите NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
Вам нужно будет сохранить выбранный индекс в переменной.