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

  • Home
  • SEARCH
  • 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 9128335
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:29:26+00:00 2026-06-17T07:29:26+00:00

So hello i’m trying to load a different UIViews in UIViewController with line like

  • 0

So hello i’m trying to load a different UIViews in UIViewController
with line like this
self.view=someView;

so here some code

- (void)viewDidLoad
{
    [self createMenuView];
}

- (void)createMenuView
{
    UIView *viewMenu=[[UIView alloc] initWithFrame:[UIScreen mainScreen].applicationFrame];
    viewMenu.backgroundColor=[UIColor grayColor];

    for(int i=0;i<3;i++){
        UIButton *Button=[UIButton buttonWithType:UIButtonTypeCustom];
        [Button setFrame:CGRectMake(0,0,320,80)];//creating it's frame
        [Button setCenter:CGPointMake(160,i*80+200)];//now place frame where we need
        [Button setTitle:[[NSString alloc] initWithFormat:@"%d",i] forState:UIControlStateNormal];//write k to title
        [Button setTag:[[[NSString alloc] initWithFormat:@"%d",i] intValue]];//write xy to tag
        [Button addTarget:self action:@selector(gameButtonClicked:) forControlEvents:UIControlEventTouchUpInside];//-event
        [Button setBackgroundImage:[UIImage imageNamed:@"blue.jpg"] forState:UIControlStateNormal];//set background
        [Button setAdjustsImageWhenHighlighted:FALSE];//disable tinting buttons while selected
        [viewMenu addSubview:Button];
    }
    self.view=viewMenu;
}

- (void)createGameView
{
    //here is just creation of a gameView which get's a whole lots of buttons
}

- (void)menuButtonClicked:(UIButton*)button
{
    [self createGameView];
}

if i do
[self createGameView]; in viewDidLoad then it’s okay
but if it’s from button then i get exception
help please

that’s what i get in output – not sure if it’s helpfull

013-01-12 18:54:19.681 Barley Break[11235:c07] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 3 beyond bounds [0 .. 2]'
*** First throw call stack:
(0x1c90012 0x10cde7e 0x1c320b4 0x4963 0x47d2 0x10e1705 0x18920 0x188b8 0xd9671 0xd9bcf 0xd8d38 0x4833f 0x48552 0x263aa 0x17cf8 0x1bebdf9 0x1bebad0 0x1c05bf5 0x1c05962 0x1c36bb6 0x1c35f44 0x1c35e1b 0x1bea7e3 0x1bea668 0x1565c 0x242d 0x2355 0x1)
libc++abi.dylib: terminate called throwing an exception
(lldb) 

UPD1:Tried to use [self setView:someView];instead of [self.view=someView]; – same exception

UPD2:
here is create gameView
ps:randExcludable – just arc4random()

- (void)createGameView
{
    UIView *viewGame=[[UIView alloc] initWithFrame:[UIScreen mainScreen].applicationFrame];
    viewGame.backgroundColor=[UIColor grayColor];

    int k=0;
    int n=4;
    int t=0,q=0;
    NSMutableArray *yEx=[[NSMutableArray alloc] initWithObjects:[[NSString alloc] initWithFormat:@"%d",5], nil],*xEx=[[NSMutableArray alloc] initWithObjects:[[NSString alloc] initWithFormat:@"%d",5], nil];

    for(int i=0;i<4;i++){
        t=[self randExclludable:n arrayToExclude:yEx];
        for(int j=0;j<4;j++){
            q=[self randExclludable:n arrayToExclude:xEx];
            UIButton *Button=[UIButton buttonWithType:UIButtonTypeCustom];//Creating button of custom type
            [Button setFrame:CGRectMake(0,0,80,80)];//creating it's frame
            [Button setCenter:CGPointMake(q*80+40,t*80+120)];//now place frame where we need
            [Button setTag:[[[NSString alloc] initWithFormat:@"%d",(t*10)+q] intValue]];//write xy to tag
            [Button setTitle:[[NSString alloc] initWithFormat:@"%d",k] forState:UIControlStateNormal];//write k to title
            [Button addTarget:self action:@selector(gameButtonClicked:) forControlEvents:UIControlEventTouchUpInside];//-event
            [Button setBackgroundImage:[UIImage imageNamed:@"blue.jpg"] forState:UIControlStateNormal];//set background
            if(i==0 && j==0){
                [Button setBackgroundImage:[UIImage imageNamed:@"gray.jpg"] forState:(UIControlStateNormal | UIControlStateDisabled)];//special background for the zero button
                [Button setEnabled:NO];//disable zero button
                [Button setTitle:@"" forState:UIControlStateNormal];//and set title of zero button to ""
            }
            [Button setAdjustsImageWhenHighlighted:FALSE];//disable tinting buttons while selected
            //[self.view addSubview:Button];//creating subview on the desired view
            //[self.buttons16 addObject:Button];//place button in array
            [viewGame addSubview:Button];
            Button=nil;
            k++;
            [xEx addObject:[[NSString alloc] initWithFormat:@"%d",q]];
        }
        [xEx removeAllObjects];
        [yEx addObject:[[NSString alloc] initWithFormat:@"%d",t]];
    }
    self.view=viewGame;
    //[self setView:viewGame];
    //[self.view addSubview:viewGame];
    viewGame=nil;
}
  • 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-17T07:29:27+00:00Added an answer on June 17, 2026 at 7:29 am

    how stupid i was saw this just now while doing the same thing now with the UINavigationToolbar and swaping the whole UIViewController
    the problem was that i gave menu buttons game buttons function which cause error because of changing the game view which is not created yet

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

Sidebar

Related Questions

Hello I have like this 2 tables class User public int UserId{get;set;} { ....
Hello there am trying to save news tweets into three different array which are
Hello! I have this trouble: I'm searching reports by date and in html view
Hello guys i am trying attempt a dynamic select here. as soon as i
hello i got a batch file, something like this: if %day%==monday, tuesday, wednesday, thursday,
Hello everybody i have asp.net mvc4 application where i made countdown something like this:
Hello I am trying to do a SOAP request here is my code: #
Hello I have a call like this list of digits(436,L). How can I reverse
Hello I'm trying to add MapView to LinearLayout this is my code: GoogleMap mMap
Hello ! I need to create a report like the attachment shows with Jasper

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.