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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:55:23+00:00 2026-06-04T20:55:23+00:00

I have put together a simple quote generator, storing the quotes in an array.

  • 0

I have put together a simple quote generator, storing the quotes in an array. Following are the quote view controller interface and implementation files:

ViewController.h

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController

@property(nonatomic, retain)NSArray *myQuotes;
@property(nonatomic, retain)NSMutableArray *movieQuotes;
@property (nonatomic, retain) IBOutlet UITextView *quote_text;

-(IBAction)quote_btn_touch:(id)sender;

@end

ViewController.m

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

@synthesize myQuotes;
@synthesize movieQuotes;
@synthesize quote_text;

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
  self.myQuotes = [NSArray arrayWithObjects:
                   @"Live and let live", 
                   @"Don't cry over spilt milk", 
                   @"Always look on the bright side of life", 
                   @"Nobody's perfect", 
                   @"Can't see the woods for the trees",
                   @"Better to have loved and lost than not loved at all",
                   @"The early bird catches the worm",
                   @"As slow as a wet week",
                   nil];

  quote_text = nil;
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
  return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

-(IBAction)quote_btn_touch:(id)sender {
  // 1 - Get number of rows in array
  int array_tot = [self.myQuotes count];
  // 2 - Get random index
  int index = (arc4random() % array_tot);
  // 3 - Get the quote string for the index 
  NSString *my_quote = [self.myQuotes objectAtIndex:index];
  // 4 - Display the quote in the text view
  self.quote_text.text = [NSString stringWithFormat:@"Quote:\n\n%@",  my_quote];      
}

@end

In the xib file, I connected the text view and button to the File’s Owner, using quote_text and quote_btn_touch respectively.

Trouble is that when I click on the button, nothing happens. Any idea what I missed?

Thanks in advance!

  • 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-04T20:55:24+00:00Added an answer on June 4, 2026 at 8:55 pm

    your setting quote text to nil on viewDidLoad. If you get rid of that your code should work as long as you correctly bound the button to the viewcontroller function

    quote_text = nil;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a custom implementation of IDataServiceMetadataProvider / IDataServiceQueryProvider / IDataServiceUpdateProvider, put together from
I've put together a simple database for storing information on awards and nominations. I've
I have put together a simple ASP.NET MVC 3 test web app that uses
Trying to do a simple web app with jquery mobile. I have put together
I'm completely new to databases, and have put something simple together using the helpful
I have put together a simple static layout where I would lilke to understand
I have a simple accordion menu I've put together today using the jQuery slideDown()
Hi guys I have put together a simple dropdown menu system that uses hoverIntent
I am a powershell novice. After days of searching.... I have put together a
Hello I have problem to put together animations of two separate objects to second

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.