Note that there are some explanatory texts on larger screens.

plurals
  1. POAdding a simple UIView from a class to the main ViewController
    text
    copied!<p>Dear scholars, code gurus.</p> <p>My question is rather simple, I have been searching and trying for some time now without any luck, I would greatly appreciate some tiny help.</p> <p>I have a simple class that should generate a view as following:</p> <pre><code>// vipcardclass.h // #import &lt;UIKit/UIKit.h&gt; @interface vipcardclass : UIViewController { } +(IBAction)newsletter; @end </code></pre> <p>and </p> <pre><code>// vipcardclass.m #import "vipcardclass.h" @implementation vipcardclass +(IBAction)newsletter{ UIView *vipcard = [[UIView alloc] initWithFrame:CGRectMake(10.0, 0.0, 290.0, 280.0)]; UIImageView *vipcardBG = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"vip_card.png"]]; //background.png [vipcard addSubview:vipcardBG]; CGRect webFrame = CGRectMake(6.0, 0.0, 300.0, 210.0); UIWebView *content = [[UIWebView alloc] initWithFrame:webFrame]; [content setBackgroundColor:[UIColor clearColor]]; [content setOpaque:NO]; NSString *urlAddress = @"http://www.google.com"; NSURL *url = [NSURL URLWithString:urlAddress]; NSURLRequest *requestObj = [NSURLRequest requestWithURL:url]; [content loadRequest:requestObj]; [vipcard addSubview:content]; [content release]; [???????? addSubview:vipcard]; NSLog(@"Newsletter was called"); } @end </code></pre> <p>(Kindly look at the ?????? , few lines above , if it was the main view controller I would use self.view addSubview: , My question is what is the proper syntax when using it from a class)</p> <p>In my main view controller I #import "vipcardclass.h"</p> <p>and at some point calling the class function [vipcardclass newsletter];</p> <p>Which works just fine, apart from adding it to the main controller. I would add as a side note, that the class functionality is not communicating or relevant to any function in the main view controller, its a fire and forget thingy and I just want to open and display this view.</p> <p>Thank you kindly.</p>
 

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