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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:51:51+00:00 2026-05-13T15:51:51+00:00

Once again working through beginning iphone development and I am putting together a bunch

  • 0

Once again working through beginning iphone development and I am putting together a bunch of UIPicker type apps, the last one of which is a slot machine type of game, super simple. Anyway I am not really understanding why this error is coming up. to my understanding the picker view is asking its delegate for an object in the array that is past the range available to that array.

That being said I have no idea why it is doing this or how to fix it, any help would be appreciated, heres the code from the particular .m file( get the full project here: http://files.me.com/knyck2/89q3w3 ):

 //
 //  CustomPickerViewController.m
 //  Pickers
 //
 //  Created by Nicholas Iannone on 1/29/10.
 //  Copyright 2010 Apple Inc. All rights reserved.
 //

 #import "CustomPickerViewController.h"


 @implementation CustomPickerViewController

 @synthesize column1, column2, column3, column4, column5, picker, winLabel;

 -(IBAction) spin : (id) sender {

NSLog(@"even got here");

BOOL win = NO;

int numInRow = 1;

int lastVal = -1;

for (int i = 0; 1 < 5; i++) {
    int newValue = random() % [self.column1 count];

    if (newValue == lastVal) {
        NSLog(@"even got here");

    numInRow++;
    }
    else 
        numInRow = 1;

        lastVal = newValue;
    [picker selectRow:newValue inComponent:i animated:YES];
    [picker reloadComponent:i];
    if (numInRow >= 3) 
        win = YES;

    NSLog(@"even got here");

}

if (win) 
    winLabel.text = @"winner!";

              else {
    winLabel.text = @"";
              NSLog(@"even got here");
              }

 }

 /*
  // The designated initializer.  Override if you create the controller programmatically                and want to perform customization that is not appropriate for viewDidLoad.
 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
    // Custom initialization
}
return self;
 }
 */


 // Implement viewDidLoad to do additional setup after loading the view, typically from      a nib.
 - (void)viewDidLoad {
UIImage *seven = [UIImage imageNamed:@"seven.png"];
UIImage *bar = [UIImage imageNamed:@"bar.png"];
UIImage *crown = [UIImage imageNamed:@"crown.png"];
UIImage *cherry = [UIImage imageNamed:@"cherry.png"];
UIImage *lemon = [UIImage imageNamed:@"lemon.png"];
UIImage *apple = [UIImage imageNamed:@"apple.png"];

    for (int i = 1; i <= 5 ;  i++) {
        UIImageView *sevenView = [[UIImageView alloc] initWithImage: seven];
        UIImageView *barView = [[UIImageView alloc] initWithImage: bar];
        UIImageView *crownView = [[UIImageView alloc] initWithImage: crown];
        UIImageView *cherryView = [[UIImageView alloc] initWithImage:      cherry];
        UIImageView *lemonView = [[UIImageView alloc] initWithImage: lemon];
        UIImageView *appleView = [[UIImageView alloc] initWithImage: apple];


        NSArray *imageViewArray = [[NSArray alloc] initWithObjects:      sevenView, barView, crownView, cherryView, lemonView, appleView, nil];
        NSString *fieldName =[[NSString alloc] initWithFormat:@"column%d",      i];
        [self setValue:imageViewArray forKey:fieldName];
        [fieldName release];
        [imageViewArray release];

        [sevenView release];
        [crownView release];
        [barView release];
        [cherryView release];
        [lemonView release];
        [appleView release];

    }

srandom(time(NULL));
[super viewDidLoad];
 }



 /*
 // Override to allow orientations other than the default portrait orientation.
 -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
 }
 */

 - (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];

// Release any cached data, images, etc that aren't in use.
 }

 - (void)viewDidUnload {
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
 }


 - (void)dealloc {
[picker release];
[winLabel release];
[column1 release];
[column2 release];
[column3 release];
[column4 release];
[column5 release];


[super dealloc];
 }


 #pragma mark -
 #pragma mark Picker Data Source Methods

 -(NSInteger) numberOfComponentsInPickerView: (UIPickerView *)  pickerView {

return 5;
 }


 -(NSInteger) pickerView: (UIPickerView *) pickerView numberOfRowsInComponent:      (NSInteger) component {

return [self.column1 count];

 }

 #pragma mark Picker Delegate Methods

 -(UIView *) pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent: (NSInteger) component reusingView : (UIView *)view {

NSString *arrayName = [[NSString alloc] initWithFormat:@"column%d", component + 1];
NSArray *array = [self valueForKey:arrayName];
NSLog(@"got here yo");
return [array objectAtIndex: row];
NSLog(@"holyshit");


 }

 @end
  • 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-13T15:51:52+00:00Added an answer on May 13, 2026 at 3:51 pm

    The reason why it’s breaking is this loop. Take a look at your for loop condition:

    1 < 5. Yes, 1 is always less than 5. This means that you have an infinite loop. I’m sure you meant i < 5.

    for (int i = 0; 1 < 5; i++) {
        int newValue = random() % [self.column1 count];
    
        if (newValue == lastVal) {
            NSLog(@"even got here");
    
        numInRow++;
        }
        else 
            numInRow = 1;
    
            lastVal = newValue;
        [picker selectRow:newValue inComponent:i animated:YES];
        [picker reloadComponent:i];
        if (numInRow >= 3) 
            win = YES;
    
        NSLog(@"even got here");
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.