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?!