Note that there are some explanatory texts on larger screens.

plurals
  1. POcustom protocol doesn't work
    primarykey
    data
    text
    <p>In the app I'm working on, I have a <code>UIViewController</code> sublcass and a <code>UIView</code> subclass. in the <code>storyboard</code> the view controller contains the <code>UIview</code>. in the uiview I'm drawing something but I need it to know some values that it should be getting from the view controller. So I created a custom protocol in the view controller .h file:</p> <pre><code>@protocol SSGraphViewControllerProtocol &lt;NSObject&gt; - (void)numberOfSemesters:(int)number; @end @property (weak, nonatomic) id &lt;SSGraphViewControllerProtocol&gt; delegate; </code></pre> <p>and in the <code>UIView</code> class I confirmed it as having the protocol above and I implemented its method. However. when I pass a number from the view controller, <code>UIView</code> doesn't receive it. Using NSLog, I figured out that <code>UIView</code> isn't entering <code>- (void)numberOfS:(int)number;</code> am I doing anything wrong? How can I fix it? and is there another way that I can send data from the <code>UIViewController</code> class to the <code>UIView</code> controller?</p> <p>Here is the full code: UIViewController.h</p> <pre><code>@protocol SSGraphViewControllerProtocol &lt;NSObject&gt; - (void)numberOfSemesters:(int)number; @end @interface SSGraphViewController : UIViewController @property (weak, nonatomic) id &lt;SSGraphViewControllerProtocol&gt; delegate; @end </code></pre> <p>UIViewController.m</p> <pre><code>@implementation SSGraphViewController - (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. [self.delegate numberOfSemesters:2]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end </code></pre> <p>UIView.h</p> <pre><code>@interface SSGraph : UIView &lt;SSGraphViewControllerProtocol&gt; @end </code></pre> <p>UIView.m</p> <pre><code>static int numberOfS = 0; @implementation SSGraph - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { // Initialization code } SSGraphViewController *graph = [[SSGraphViewController alloc] init]; graph.delegate = self; return self; } - (void) numberOfSemesters:(int)number{NSLog(@"YES"); numberOfSemesters= number; } // Only override drawRect: if you perform custom drawing. // An empty implementation adversely affects performance during animation. - (void)drawRect:(CGRect)rect { } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload