1

スキャンしたQRコードを取得して、コードが表すアイテムに関する情報を含むViewControllerを表示しようとしています。詳細ビューコントローラにセグエしようとすると、次のようになります。

Warning: Attempt to present <MachinesDetailViewController: 0x1e5bfc50> on <UITabBarController: 0x1f867d90> whose view is not in the window hierarchy!

MainViewControllerはメインタブバーコントローラーを使用していますが、詳細ビューコントローラーはタブバーコントローラーを使用しているナビゲーションコントローラー内にあります。

これが私のMainViewController.mです。

    //
//  FirstViewController.m
//  Fitness Plus+
//
//  Created by Tom Brereton on 26/01/13.
//  Copyright (c) 2013 Tom Brereton. All rights reserved.
//

#import "MainViewController.h"
#import "MachinesDetailViewController.h"
@interface MainViewController ()

@end

@implementation MainViewController

@synthesize resultText, machineKeys, codeInt, machineArea, machineName;

- (IBAction)scanButton:(id)sender {

    NSLog(@"ehe");
    // ADD: present a barcode reader that scans from the camera feed
    ZBarReaderViewController *reader = [[ZBarReaderViewController alloc] init];
    reader.readerDelegate = self;
    reader.supportedOrientationsMask = ZBarOrientationMaskAll;

    ZBarImageScanner *scanner = reader.scanner;
    // TODO: (optional) additional reader configuration here

    // EXAMPLE: disable rarely used I2/5 to improve performance
    [scanner setSymbology: ZBAR_I25
                   config: ZBAR_CFG_ENABLE
                       to: 0];
    NSLog(@"Got here");
    // present and release the controller

    [self presentViewController: reader
                            animated: YES
                            completion:nil];


}

- (void) imagePickerController: (UIImagePickerController*) reader
 didFinishPickingMediaWithInfo: (NSDictionary*) info
{
    // ADD: get the decode results
    id<NSFastEnumeration> results =
    [info objectForKey: ZBarReaderControllerResults];
    ZBarSymbol *symbol = nil;
    for(symbol in results)
        // EXAMPLE: just grab the first barcode
        break;
    NSLog(@"Naht Here");

    // EXAMPLE: do something useful with the barcode data

    // Scan the machines.plist array and print it to the console.
    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"machines" ofType:@"plist"];
    NSDictionary *machineDict = [NSDictionary dictionaryWithContentsOfFile:filePath];
    machineKeys = [machineDict objectForKey:@"Exercises"];
    machineArea = [machineDict objectForKey:@"Area"];
    resultText.text = symbol.data;

    //Convert code into integer value and put it inside codeInt
    codeInt = [symbol.data intValue];

    NSLog(@"Scanned Value: %@", [machineKeys objectAtIndex:codeInt]);
    // EXAMPLE: do something useful with the barcode image
    [self performSegueWithIdentifier:@"showDetailFromMain" sender:reader];
    // ADD: dismiss the controller (NB dismiss from the *reader*!)
    [self dismissViewControllerAnimated:YES completion:nil];


}


- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)reader {
    if ([[segue identifier] isEqualToString:@"showDetailFromMain"]) {
        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
        MachinesDetailViewController *machineViewController = [storyboard instantiateViewControllerWithIdentifier:@"showMachineDetailViewController"];

        machineViewController = [segue destinationViewController];


        machineName = [machineKeys objectAtIndex:codeInt];
        [machineViewController setMachineNameLabel: machineName];
         }
}

- (void) viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

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



@end

ZBarのものは、QRスキャンAPIに関連しています。

そして、これがMachineDetailsViewController.mです。

//
//  MachinesDetailViewController.m
//  Fitness Plus+
//
//  Created by Tom Brereton on 27/01/13.
//  Copyright (c) 2013 Tom Brereton. All rights reserved.
//

#import "MachinesDetailViewController.h"
@interface MachinesDetailViewController ()
@property(nonatomic, copy) NSString *title;
@end

@implementation MachinesDetailViewController
@synthesize machineLabel, machineName, instructionsLabel, typeLabel, mainMuscleLabel, otherMuscleLabel, equipmentLabel, machineDictionary, machineArray, mainMuscleLabelString, instructionLabelString, typeLabelString, otherMuscleLabelString, equipmentLabelString, title, machineNameLabel;

- (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.
    // Set the Label text with the selected machine name
    machineName = machineNameLabel;
    mainMuscleLabel.text = mainMuscleLabelString;
    otherMuscleLabel.text = otherMuscleLabelString;
    equipmentLabel.text = equipmentLabelString;
    typeLabel.text = typeLabelString;
    instructionsLabel.text = instructionLabelString;
    self.navigationItem.title = machineName;
    NSLog(@"got it");

}

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

@end

ありがとう、あなたがより多くの情報を必要とするならば、ただ尋ねてください。

  • トム
4

1 に答える 1