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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T13:36:07+00:00 2026-05-19T13:36:07+00:00

Alright, so to get going with Objective-C (I’m usually just an HTML PhoneGap kinda

  • 0

Alright, so to get going with Objective-C (I’m usually just an HTML PhoneGap kinda guy), I made a simple Magic 8 ball app. I’ve got it right now so that when I touch the screen, the ball “shakes” and takes a random response and puts it in a label. What I want to do is when the iPhone itself is shaked, the text is updated too.

Here’s my MainView.m:

#import "MainView.h"

@implementation MainView

- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {
 if (event.type == UIEventSubtypeMotionShake) {
  int rNumber = rand() % 26;
  switch (rNumber) {
                case 0:
                    shook.text = @"Never";
                    break;
            ....25 more entries.....
                default:
                    break;
           }
    }
 }

 - (IBAction)yesNo {
 [NSThread sleepForTimeInterval:0.75];
 int rNumber = rand() % 26;
 switch (rNumber) {
  case 0:
   result.text = @"Never";
   break;
  ........
  default:
  break;
 }
 }

 @end

and my MainView.h

 #import <UIKit/UIKit.h>
 #import <Foundation/Foundation.h>

 @interface MainView : UIView <UIAccelerometerDelegate> {
     IBOutlet UILabel *result;
  IBOutlet UILabel *shook;
 }

 - (IBAction)yesNo;
 - (void)motionEnded;

 @end     

Obviously there’s an error in there, I know that much, but where?!

  • 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-19T13:36:08+00:00Added an answer on May 19, 2026 at 1:36 pm

    It looks like you need to read the documentation in more depth to get to the bottom of this. Specifically the iOS Event Handling Guide.

    From that document there are a few things which I would suggest you try:

    1. Override canBecomeFirstResponder: and return YES (as per Listing 4-1).
    2. Override viewDidAppear:animated: to become the first responder (as per Listing 4-1).
    3. Override both motionBegan:withEvent: and motionCancelled:withEvent: as they do this in the example which may be because the framework is testing your view controller class to see if it responds to these selectors (as per Listing 4-2).

    Look at the UIResponder Class Reference (from which UIViewController inherits) for more detail on the methods you are overriding.

    As someone who came from a Microsoft / VB / .NET and Android / Java background to Cocoa / Objective-C programming I would strongly suggest you invest the time in reading the documentation. Initially the Apple documents seem impenetrable but they’re actually pretty good!

    I hope that helps.

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

Sidebar

Related Questions

Alright, I know this is a simple question, but I can't seem to get
Alright, turns out I suck at Encryption/Decryption. I just dont get it. How can
Alright, I'm trying to get arguments to work properly with a small test application.
Alright, here is the output I get: arm-none-linux-gnueabi-ld --entry=main -dynamic-linker=/system/bin/linker -rpath-link=/home/oem/android-ndk-r3/build/platforms/android-5/arch-arm/usr/lib -L/home/oem/android-ndk-r3/build/platforms/android-5/arch-arm/usr/lib -nostdlib -lstdc++
Alright. So I figure it's about time I get into unit testing, since everyone's
Alright, I know how the fieldset / legend works out in HTML. Say you
I'm having some trouble sending $_FILES by cURL - the files get transferred alright
I'm alright with basic regular expressions, but I get a bit lost around pos/neg
Alright so I'm just trying to open a basic window with GLFW, and while
Alright, I am going for the total shotgun question here. I tried to create

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.