• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: iPhone: Question in regards to a UIView accessing AppDelegate
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: iPhone: Question in regards to a UIView accessing AppDelegate


  • Subject: Re: iPhone: Question in regards to a UIView accessing AppDelegate
  • From: Mike Abdullah <email@hidden>
  • Date: Wed, 23 Dec 2009 20:32:26 +0000



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
_______________________________________________

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


  • Follow-Ups:
    • Re: iPhone: Question in regards to a UIView accessing AppDelegate
      • From: "Eric E. Dolecki" <email@hidden>
References: 
 >iPhone: Question in regards to a UIView accessing AppDelegate (From: "Eric E. Dolecki" <email@hidden>)

  • Prev by Date: iPhone: Question in regards to a UIView accessing AppDelegate
  • Next by Date: There must be a better way
  • Previous by thread: iPhone: Question in regards to a UIView accessing AppDelegate
  • Next by thread: Re: iPhone: Question in regards to a UIView accessing AppDelegate
  • Index(es):
    • Date
    • Thread