Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1025719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:58:14+00:00 2026-05-16T11:58:14+00:00

Dear scholars, code gurus. My question is rather simple, I have been searching and

  • 0

Dear scholars, code gurus.

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.

I have a simple class that should generate a view as following:

//  vipcardclass.h

//

#import <UIKit/UIKit.h>


@interface vipcardclass : UIViewController {

}
+(IBAction)newsletter;
@end

and

//  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

(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)

In my main view controller I
#import “vipcardclass.h”

and at some point calling the class function
[vipcardclass newsletter];

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.

Thank you kindly.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T11:58:14+00:00Added an answer on May 16, 2026 at 11:58 am

    Try This:

    //  vipcardclass.m
    
    #import "vipcardclass.h"
    
    
    @implementation vipcardclass
    
    
    
    + (UIView*) 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];     
        [vipcardBG release];
    
    
        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]; 
    
        NSLog(@"Newsletter was called");
    
        return [vipcard retain];
    
    
    
    }
    @end
    

    And in the main View Controller:

    - (IBAction) loadNewsletter
    {
        UIView *vipcard = [vipcardclass newsletter];
        [self.view addSubview:vipcard];
        [vipcard release];
    
    }
    

    Additionally, you may actually want to subclass UIView and include all the code in newsletter into the init method:

    @interface vipcardclass : UIView {
    
    }
    @end
    
    @implementation vipcardclass
    
     - (id) init {
        self = [super init];
        if (self != nil) {
    
            UIImageView *vipcardBG =[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"vip_card.png"]];
       //background.png
           [self addSubview:vipcardBG];     
           [vipcardBG release];
    
    
           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]; 
           [self addSubview:content]; 
           [content release]; 
    
           NSLog(@"Newsletter was called");
        }
        return self;
    }
    
    @end
    

    And in the main View Controller:

    - (IBAction) loadNewsletter
    {
        UIView *vipcard = [[vipcardclass alloc] init];
        [self.view addSubview:vipcard];
        [vipcard release];
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Dear g++ hackers, I have the following question. When some data of an object
Dear Stacktoverflow, can you show me an example of how to use a QScrollBar?
Given a document written with normal quotes, e.g. Ben said buttons, dear sir. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.