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 9155791
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:39:24+00:00 2026-06-17T12:39:24+00:00

I am wanting to create a custom UIView class that will show a dynamic

  • 0

I am wanting to create a custom UIView class that will show a dynamic number of UISegmentedControl objects depending on some input. For example, if a client has 5 products in their cart, the UIView should generate 5 UISegmentedControl objects that I will then link with each item.

The problem I am having is getting this to work in a UIView. Here is what I have done so far. I am successfully able to create a UISegmentedControl object and display it programmatically within my main UIViewController. I don’t get any display when adding it to my UIView class. Here is the implementation code for the UIView class:

#import "ajdSegmentView.h"

@implementation ajdSegmentView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        NSArray *itemArray = [NSArray arrayWithObjects:@"Yes", @"No", nil];

        UISegmentedControl *button = [[UISegmentedControl alloc] initWithItems:itemArray];
        button.frame = CGRectMake(35,44, 120,44);
        button.segmentedControlStyle = UISegmentedControlStylePlain;
        button.selectedSegmentIndex = 1;

        [self addSubview:button];
    }
    return self;
}
@end

I created a new UIView object via Storyboard and placed it inside the UIViewController scene. I made sure to set the class from the generic UIView class to my new custom class. I added and outlet for the UIView in my UIViewController class. Here is the code inside the implementation of UIViewController:

#import "ajdViewController.h"

@interface ajdViewController ()

@end

@implementation ajdViewController

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

    self.segmentView = [[ajdSegmentView alloc] init];
}

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

@end

That’s all I have tried. I have been searching through a lot of pages and trying to implement this without asking here, but I seem to be looking in the wrong places.

  • 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-06-17T12:39:25+00:00Added an answer on June 17, 2026 at 12:39 pm

    You’re initializing your custom view using the init method, but your initialization for ajdSegmentView is in your initWithFrame: method (which in your case is not getting called).

    So replace:

    self.segmentView = [[ajdSegmentView alloc] init];
    

    with:

    // Change the frame to what you want
    self.segmentView = [[ajdSegmentView alloc] initWithFrame:CGRectMake(0,0,100,40)];
    

    Also don’t forget to add your view to the view controller’s view also.

    [self.view addSubview:self.segmentView];
    

    Unless this view is being created with interface builder, in which case you will need to override initWithCoder: in your ajdSegmentView class.

    I’m not familiar with Storyboard though, so maybe I’m missing something, but in a standard scenario what I said above will solve your problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to create a mapping from objects of my own custom class (derived
I'm wanting to create a WoW cooldown effect where a player does some action
I am wanting to create a VB.Net app that checks a database and then
Wanting to create custom data annotation validation. Are there any useful guides / samples
Basically I'm wanting to create a GPS system for my car that works offline,
I am wanting to create a Model that has a property of Service which
I have a custom gallery plugin that I have created and I am wanting
I'm wanting to create something that moves akin to Springboard, so a paginated UIScrollView
Totally new to custom control creation in Silverlight. I'm wanting a custom control that
I am wanting to create a Custom Document Library for the purpose of targeting

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.