Re: iPhone: Question in regards to a UIView accessing AppDelegate
Re: iPhone: Question in regards to a UIView accessing AppDelegate
- Subject: Re: iPhone: Question in regards to a UIView accessing AppDelegate
- From: "Eric E. Dolecki" <email@hidden>
- Date: Wed, 23 Dec 2009 15:41:27 -0500
I JUST discovered that - thanks. THAT caused my EXC_BAD_ACCESS? I spent 2
hours looking and digging and finally NSLogged the app delegate so I knew I
had it... and figured it was on the other end.
Happy Holidays everyone. I'm too angry at myself to continue for the day.
On Wed, Dec 23, 2009 at 3:32 PM, Mike Abdullah <email@hidden>wrote:
>
>
> Mike.
>
> Sent from my iPhone
>
>
> On 23 Dec 2009, at 07:45 PM, "Eric E. Dolecki" <email@hidden> wrote:
>
> I have a main view. It calls up a subView (UIView) like so:
>>
>> In the .m of the view controller:
>>
>> #import "SettingsView.h" //this is my UIView class
>> ...
>>
>> NSArray *nibViews = [[NSBundle mainBundle] loadNibNamed:@"Settings"
>> owner:
>> self options:nil];
>>
>> SettingsView *settingsView = (SettingsView *)[nibViews objectAtIndex:0];
>>
>> [self.view addSubview:settingsView];
>>
>>
>> This seems to work. initWithCoder gets called, then drawRect. The xib
>> really
>> only contains a UIImageView with a background image in it. In the
>> SettingsView class I have code that sets up it's UI:
>>
>>
>> .h:
>>
>>
>> #import <UIKit/UIKit.h>
>>
>>
>> @interface SettingsView : UIView {
>>
>> }
>>
>> @end
>>
>>
>> .m:
>>
>> #import "SettingsView.h"
>>
>> #import "AnalogAppDelegate.h"
>>
>>
>> - (void) pickOne:(id)sender {
>>
>> //This doesn't seem to want to work
>>
>> AnalogAppDelegate *appDelegate = (AnalogAppDelegate *)[[UIApplication
>> sharedApplication] delegate];
>>
>> switch ( [((UISegmentedControl *)sender) selectedSegmentIndex]) {
>>
>> case 0:
>>
>> [appDelegate stopSleep:YES]; //crashes app
>>
>> break;
>>
>> case 1:
>>
>> [appDelegate stopSleep:NO]; //crashes app
>>
>> break;
>>
>> }
>>
>> }
>>
>>
>> - (void)layoutSubviews {
>>
>> UIButton * btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
>>
>> btn.frame = CGRectMake(120, 300, 80, 30);
>>
>> [btn setTitle:@"OK" forState:UIControlStateNormal];
>>
>> [btn addTarget:self action:@selector(aMethod:)
>> forControlEvents:UIControlEventTouchDown];
>>
>> [self addSubview:btn];
>>
>> NSArray *itemArray = [NSArray arrayWithObjects: @"Enabled", @"Disabled",
>> nil];
>>
>> UISegmentedControl *segmentedControl = [[UISegmentedControl alloc]
>> initWithItems:itemArray];
>>
>> segmentedControl.frame = CGRectMake(40, 44, 240, 29);
>>
>> segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
>>
>> segmentedControl.selectedSegmentIndex = 1;
>>
>> [segmentedControl addTarget:self action:@selector(pickOne:)
>> forControlEvents:UIControlEventValueChanged];
>>
>> [self addSubview:segmentedControl];
>>
>> }
>>
>>
>> - (void) aMethod:(id)sender {
>>
>> [self removeFromSuperview];
>>
>> }
>>
>> In the AnalogAppDelegate I have this simple method:
>>
>> .h:
>>
>> - (void) stopSleep:(BOOL)shouldStop;
>> .m:
>>
>> - (void) stopSleep:(BOOL)shouldStop {
>>
>> NSLog(@"stop sleep %@", shouldStop);
>>
>> }
>>
>
> %@ is for objects. You're trying to use it for a BOOL.
>
>>
>> I am wondering why the app crashes when I try this. I don't see anything
>> in
>> the debug console, it just dies.
>>
>> --
>> http://ericd.net
>> Interactive design and development
>> _______________________________________________
>>
>> Cocoa-dev mailing list (email@hidden)
>>
>> Please do not post admin requests or moderator comments to the list.
>> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>>
>> Help/Unsubscribe/Update your Subscription:
>>
>>
>> This email sent to email@hidden
>>
>
--
http://ericd.net
Interactive design and development
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden