У меня есть UILabel(descriptionOfProgram)
на секунду ViewController(GraphViewController)
, который должен быть установлен, когда происходит переход от исходного MVC.
В настоящее время в моем основном MVC я делаю две вещи в своем prepareForSegue:
:
- Я установил
@property NSString
в GraphVewController для строки, которой я хочу, чтобы она была.1010 * - Я установил текст descriptionOfProgram равным этой строке, вызвав функцию в
GraphViewController setDescriptionLabel:
.
Когда graphViewController
входит в строку, текст отсутствует в метке.Во время тестирования я создал кнопку с именем test
в GraphViewController
для вызова setDescriptionLabel
при нажатии.Это сработало.Любые идеи о том, что происходит?
Я включил GraphViewController.h
и .m
во второй MVC и GraphingCalculatorViewController.m
в основной MVC.
GraphViewController.h:
//
// GraphViewController.h
// GraphingCalculator
//
// Created by Graham Gaylor on 3/1/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface GraphViewController : UIViewController
@property (nonatomic,copy) NSArray *program;
@property (nonatomic,weak) NSString *description;
@property (weak, nonatomic) IBOutlet UILabel *descriptionOfProgram;
- (IBAction)test:(id)sender;
- (void)setDescriptionLabel:(NSString *)description;
@end
GraphViewController.m:
//
// GraphViewController.m
// GraphingCalculator
//
// Created by Graham Gaylor on 3/1/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#import "GraphViewController.h"
#import "GraphView.h"
@interface GraphViewController() <GraphViewDataSource>
@property (nonatomic, weak) IBOutlet GraphView *graphView;
@end
@implementation GraphViewController
@synthesize program = _program;
@synthesize descriptionOfProgram = _descriptionOfProgram;
@synthesize description = _description;
@synthesize graphView = _graphView;
- (void)setProgram:(NSArray *)program
{
_program = program;
[self.graphView setNeedsDisplay]; // any time our Model changes, redraw our View
self.graphView.dataSource = self; // setting graphView delegate GraphVC
}
- (IBAction)test:(id)sender {
self.descriptionOfProgram.text = @"test";
[self setDescriptionLabel:self.description];
}
- (void)setDescriptionLabel:(NSString *)description
{
NSLog(@"Got into setDescriptionLabel");
self.descriptionOfProgram.text = @"hello";
}
- (NSArray *)programForGraphView:(GraphView *)sender {
return self.program;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
- (void)viewDidUnload {
[self setDescriptionOfProgram:nil];
[super viewDidUnload];
}
@end
Это мой основной MVC.Я избавился от всех дополнительных функций, которые не имеют отношения к seque.
GraphingCalculatorViewController.m:
//
// GraphingCalculatorViewController.m
// GraphingCalculator
//
// Created by Graham Gaylor on 3/1/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#import "GraphingCalculatorViewController.h"
#import "GraphViewController.h"
@interface GraphingCalculatorViewController()
@property (nonatomic,strong) NSArray *programToGraph;
@end
@implementation GraphingCalculatorViewController
@synthesize programToGraph = _programToGraph;
- (void)setAndShowGraph:(NSArray *)program {
self.programToGraph = program;
[self performSegueWithIdentifier:@"ShowGraph" sender:self];
NSLog(@"setAndShowGraph");
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if([segue.identifier isEqualToString:@"ShowGraph"]) {
[segue.destinationViewController setProgram:self.programToGraph]; // sets GraphVC's program to current program
[segue.destinationViewController setDescriptionLabel:[CalculatorBrain descriptionOfProgram:self.programToGraph]];
NSLog(@"prepareForSegue");
}
}
- (IBAction)graphPressed {
[self setAndShowGraph:self.brain.program];
}
- (void)viewDidUnload {
[self setVariablesUsed:nil];
[super viewDidUnload];
}
@end