UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 75, 25)];
label.textAlignment = UITextAlignmentRight;
label.tag = kLabelTag;
label.font = [UIFont boldSystemFontOfSize:14];
label.text = #"Lawn Sign";
[cell.contentView addSubview:label];
[label release];
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:nil];
NSArray * item = [ NSArray arrayWithObjects:#"No",#"Install",#"Replace",#"Move", nil];
[segmentedControl initWithItems:item];
segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
segmentedControl.frame = CGRectMake(90, 10, 200, 30);
[segmentedControl setMomentary:YES];
[segmentedControl addTarget:self action:#selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
segmentedControl.tag = 14;
[cell.contentView addSubview:segmentedControl];
[segmentedControl release];
Here's my UISegmentedControl configuration for a cell in the tableview but when I tap on an option in the segmentedControl, it doesn't switch.
You've set the control to be momentary. Change this:
[segmentedControl setMomentary:YES];
to this:
[segmentedControl setMomentary:NO];
and the control will show its selected state.
Related
I am developing one application for iphone and in that i have some issues regarding adding more then one UILabel in navigation bar at a specific position.
What i want is in following images
in above image there is one backbar button and one imageview as shown with arrow-mark. Other then that all white box is for difrent UILabels to show in navigation bar.
There is only one UIImageView in the navigation bar and one left bar button. Now problem is that i don't know how to add multiple UILabel in navigation bar at a specific position.
Till now what i have worked is to add only button and UIImageView with the right bar button array or left bar button array, but that only add items in sequnce.
So can anyone please guide me that how can anyone add UILabels or any other item at a specific position..
you can add Multiple UIlabel or Image as look like bellow image:-
this can do using bellow code you can change Label and imageView frame and put as your requirement
- (void)viewDidLoad
{
UIView *btn = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 60)];
UILabel *label;
label = [[UILabel alloc] initWithFrame:CGRectMake(5, 25, 200, 16)];
label.tag = 1;
label.backgroundColor = [UIColor clearColor];
label.font = [UIFont boldSystemFontOfSize:16];
label.adjustsFontSizeToFitWidth = NO;
label.textAlignment = UITextAlignmentLeft;
label.textColor = [UIColor whiteColor];
label.text = #"My first lable";
label.highlightedTextColor = [UIColor whiteColor];
[btn addSubview:label];
[label release];
label = [[UILabel alloc] initWithFrame:CGRectMake(0, 30, 200, 16)];
label.tag = 2;
label.backgroundColor = [UIColor clearColor];
label.font = [UIFont boldSystemFontOfSize:16];
label.adjustsFontSizeToFitWidth = NO;
label.textAlignment = UITextAlignmentRight;
label.textColor = [UIColor whiteColor];
label.text = #"second line";
label.highlightedTextColor = [UIColor whiteColor];
[btn addSubview:label];
[label release];
UIImageView *imgviw=[[UIImageView alloc]initWithFrame:CGRectMake(170, 10, 20, 20)];
imgviw.backgroundColor = [UIColor blackColor];
imgviw.image=[UIImage imageNamed:#"a59117c2eb511d911cbf62cf97a34d56.png"];
[btn addSubview:imgviw];
self.navigationItem.titleView = btn;
}
You can add subviews directly to the navigationBar -
UINavigationBar *navBar = navController.navigationBar;
[navBar addSubview: yourLabel];
yourLabel frame origin will be relative to the navigation bar
Try this code
UIView *buttonContainer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 44)];
buttonContainer.backgroundColor = [UIColor clearColor];
UIButton *button0 = [UIButton buttonWithType:UIButtonTypeCustom];
[button0 setFrame: CGRectMake(160, 7 , 40, 30)];
[button0 setTitle:#"Sort" forState:UIControlStateNormal];
button0.titleLabel.font = [UIFont fontWithName:#"Helvetica" size:12];
[button0 setBackgroundImage:[UIImage imageNamed:#"Btn_Sort_Btn_Sort_Places.png"] forState:UIControlStateNormal];
[button0 addTarget:self action:#selector(sortAction) forControlEvents:UIControlEventTouchUpInside];
[button0 setShowsTouchWhenHighlighted:YES];
[buttonContainer addSubview:button0];
self.navigationItem.titleView = buttonContainer;
UILabel *lbl_title = [[UILabel alloc] initWithFrame:CGRectMake(10, 0 , 140, 40)];
lbl_title.text = str_HeaderTitle;
lbl_title.textColor = [UIColor whiteColor];
lbl_title.font = [UIFont fontWithName:#"Helvetica-Bold" size:16];
lbl_title.backgroundColor = [UIColor clearColor];
lbl_title.textAlignment = NSTextAlignmentCenter;
[buttonContainer addSubview:lbl_title];
You can set an arbitrary view instead of a view controller's title:
myViewController.navigationItem.titleView = someView;
Note that most likely the view's frame will be restricted to make room for leftBarButtonItem and rightBarButtonItem.
UILabel *label=[[UILabel alloc] initWithFrame:CGRectMake(50, 2, 20, 15)];
[label setBackgroundColor:[UIColor greenColor]];
UIImageView *imgView=[[UIImageView alloc] initWithFrame:CGRectMake(40, 20, 150, 10)];
[imgView setBackgroundColor:[UIColor redColor]];
[[self.navigationController navigationBar] addSubview:label];
[self.navigationController.navigationBar addSubview:imgView];
Have a look at this piece of code. With some modifications it should solve your problem:
UIButton *imageButton = [UIButton buttonWithType:UIButtonTypeCustom];
[imageButton setFrame:CGRectMake(15, 0, 57, 44)];
[imageButton setBackgroundImage:[UIImage imageNamed:#"someImage.png"] forState:UIControlStateNormal];
UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(140, 0, 250, 44)];
[titleLabel setText:#"some title"];
[titleLabel setBackgroundColor:[UIColor clearColor]];
[titleLabel setTextColor:[UIColor whiteColor]];
[titleLabel setFont:[UIFont boldSystemFontOfSize:20]];
[self.navigationController.navigationBar addSubview:imageButton];
[self.navigationController.navigationBar addSubview:titleLabel];
Just modify the values in the CGRectMake() to fit your needs.
I am facing trouble unexpected issue in iphone app. for whatever reason, I compile this, I get a SIGABRT error. it happens on the:
textFieldRounded=[[UITextField alloc]initWithframe: CGRectMake(20,50,280,31)];
textFieldRounded.borderStyle=UITextBorderStyleRoundedRect;
textFieldRounded.textColor=[UIColor blackColor];
textFieldRounded.font=[UIFont systemFontOfSize:17.0];
textFieldRounded.placeholder=#"enter your name";
textFieldRounded.backgroundColor=[UIColor whiteColor];
textFieldRounded.autocorrectionType=UITextAutocorrectionTypeNo;
textFieldRounded.backgroundColor=[UIColor clearColor];
textFieldRounded.keyboardType=UIKeyboardTypeDefault;
textFieldRounded.returnKeyType=UIReturnKeyDone;
textFieldRounded.clearButtonMode=UITextFieldViewModeWhileEditing;
[self.view addSubView:textFieldRounded];
textFieldRounded.delegate=self;
UIButton *button =[UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self action:#selector(buttonPressed:)
forControlEvents:UIControlEventTouchDown];
[button setTitle:#"Button" forstate:UIControlStateNormal];
button.frame = CGRectMake(20,108,97,37);
[self.view addSubview:button];
label= [[UILabel alloc] initWithFrame:CGRectMake(40,243,240,21)];
label.backgroundColor=[UIColor clearColor];
label.textAlignment,UITextAlignmentCenter;
label.text=#"Label";
[self.view addSubview:label];
CGRect myImageRect = CGRectMake(40.0f,190.0f,240.0f,128.0f);
image= [[UIImageView alloc] initWithFrame:myImageRect];
[image setImage:[UIImage imageNamed:#"Default#2x.png"]];
image.backgroundColor=[UIColor clearColor];
image.opaque =YES;
image.alpha=0;
[self.view addSubview:image];
[image release];
}
you can Creat UITextField, UIButton or UILabel like this bellow code:-
UITextField
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(10, 200, 300, 40)];
textField.borderStyle = UITextBorderStyleRoundedRect;
textField.font = [UIFont systemFontOfSize:15];
textField.placeholder = #"enter text";
textField.autocorrectionType = UITextAutocorrectionTypeNo;
textField.keyboardType = UIKeyboardTypeDefault;
textField.returnKeyType = UIReturnKeyDone;
textField.clearButtonMode = UITextFieldViewModeWhileEditing;
textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
textField.delegate = self;
[self.view addSubview:textField];
[textField release];
UIButton
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self action:#selector(aMethod:) forControlEvents:UIControlEventTouchUpInside];
[button setTitle:#"UIButton" forState:UIControlStateNormal];
button.frame = CGRectMake(80.0, 210.0, 160.0, 40.0);
[view addSubview:button];
[button release];
UILabel
UILabel *headingLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 240, 300, 30)];
[self.view addSubview:headingLabel];
// Optional
headingLabel.text = #"WELCOME";
headingLabel.textColor = [UIColor orangeColor];
headingLabel.textAlignment = UITextAlignmentCenter;
headingLabel.tag = 10;
headingLabel.backgroundColor = [UIColor clearColor];
headingLabel.font = [UIFont fontWithName:#"MarkerFelt-Thin" size:14.0];
headingLabel.hidden = NO;
headingLabel.highlighted = YES;
headingLabel.highlightedTextColor = [UIColor blueColor];
headingLabel.lineBreakMode = YES;
headingLabel.numberOfLines = 0;
UIImageView
UIImageView *myImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 150, 150)];
myImage.image = [UIImage imageNamed:#"myImage.png"];
[self.view addSubview:myImage];
[mymyImage release];
Hope its helps you
I have created a View containing labels and buttons with Controller.
By using addSubView method my view appears but button does not respond to view controller.. Can anybody help me doing what I want to do??
I have used this code to add view as subview in my alert view.
[myAlertView addSubview:myViewController.view];
You need to add an action on your button like below.
[yourButton addTarget:self action:#selector(myAction) forControlEvents:UIControlEventTouchUpInside];
- (IBAction) myAction
{
//Action to perform when yourButton pressed.
}
Hope this helps you!
myview=[[UIView alloc] init];
[myview setFrame:CGRectMake( 50.0f, 50.0f, 120.0f, 120.0f)];
[UIView commitAnimations];
[UIView beginAnimations:#"animateTableView" context:nil];
[UIView setAnimationDuration:0.7];
[myview setFrame:CGRectMake( 90.0f, 20.0f, 280.0f, 170.0f)];
myview.backgroundColor=[UIColor whiteColor];
//myview.frame = CGRectMake(10, 10, 200, 250);
[self.view addSubview:myview];
UIColor *forBackground = [UIColor colorWithPatternImage:[UIImage imageNamed:#"apple_bg.png"]];
[myview setBackgroundColor:forBackground];
myview.layer.cornerRadius=20;
myview.clipsToBounds=YES;
myview.layer.borderWidth = 2;
myview.layer.borderColor = [[UIColor whiteColor] CGColor];
UITextView *mytext = [[UITextView alloc] initWithFrame:CGRectMake(5.0, 10.0, 160.0, 25.0)];
mytext.backgroundColor = [UIColor clearColor];
mytext.textColor = [UIColor blackColor];
mytext.editable = NO;
mytext.scrollEnabled=NO;
mytext.scrollEnabled=NO;
mytext.font = [UIFont systemFontOfSize:15];
mytext.text = #"First label";
[mytext release];
[myview addSubview:mytext];
entered = [[UITextField alloc] initWithFrame:CGRectMake(120.0, 15.0, 150.0, 25.0)];
[entered setBackgroundColor:[UIColor whiteColor]];
entered.layer.cornerRadius = 10;
entered.textAlignment = UITextAlignmentCenter;
entered.clipsToBounds = YES;
[entered addTarget:self action:#selector(textDidChange:)forControlEvents:UIControlEventEditingChanged];
[myview addSubview:entered];
UITextView *mytext2 = [[UITextView alloc] initWithFrame:CGRectMake(5.0, 50.0, 160.0, 25.0)];
mytext2.backgroundColor = [UIColor clearColor];
mytext2.textColor = [UIColor blackColor];
mytext2.editable = NO;
mytext2.scrollEnabled=NO;
mytext2.font = [UIFont systemFontOfSize:15];
mytext2.text = #"Second label";
[myview addSubview:mytext2];
[mytext2 release];
entered1 = [[UITextField alloc] initWithFrame:CGRectMake(120.0, 55.0, 150.0, 25.0)];
[entered1 setBackgroundColor:[UIColor whiteColor]];
entered1.layer.cornerRadius = 10;
entered1.textAlignment = UITextAlignmentCenter;
entered1.clipsToBounds = YES;
[myview addSubview:entered1];
[entered1 release];
UITextView *mytext3 = [[UITextView alloc] initWithFrame:CGRectMake(5.0, 90.0, 160.0, 25.0)];
mytext3.backgroundColor = [UIColor clearColor];
mytext3.textColor = [UIColor blackColor];
mytext3.editable = NO;
mytext3.scrollEnabled=NO;
mytext3.font = [UIFont systemFontOfSize:15];
mytext3.text = #"Third Label";
[myview addSubview:mytext3];
[mytext3 release];
entered2 = [[UITextField alloc] initWithFrame:CGRectMake(120.0, 95.0, 150.0, 25.0)];
[entered2 setBackgroundColor:[UIColor whiteColor]];
entered2.layer.cornerRadius = 10;
entered2.clipsToBounds = YES;
entered2.text=#"Active";
entered2.textAlignment = UITextAlignmentCenter;
[myview addSubview:entered2];
[entered2 release];
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self action:#selector(EditTable:)
forControlEvents:UIControlEventTouchDown];
[button setTitle:#"Ok" forState:UIControlStateNormal];
button.frame = CGRectMake(60.0, 130, 60, 30);
[myview addSubview:button];
UIButton *button1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button1 addTarget:self action:#selector(EditTable1:)
forControlEvents:UIControlEventTouchDown];
[button1 setTitle:#"Cancel" forState:UIControlStateNormal];
button1.frame = CGRectMake(150.0, 130, 60, 30);
[myview addSubview:button1];
[self.view addSubview: myview];
I want to insert one button and one label in my NavigationBar in iOS.
I have tried with UISegmentedControl and it works completely fine with one control!
Now the problem is I want to add multiple controls as i have said before How can I?
Look at my code
UIView *v;
[v insertSubview:listingsLabel atIndex:0];
[v insertSubview:shareBtn atIndex:1];
[v setFrame:[self.navigationController.toolbar bounds]];
self.navigationItem.titleView = v;
v.frame = CGRectMake(0, 0, 200, 29);
and it gives me error of EXC_BAD_ACCESS
UIToolbar* tools = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 100, 44.01)];
// create the array to hold the buttons, which then gets added to the toolbar
NSMutableArray* buttons = [[NSMutableArray alloc] initWithCapacity:3];
// create a standard "add" button
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:[NSArray array]];
[segmentedControl insertSegmentWithTitle:#"All" atIndex:0 animated:NO];
[segmentedControl insertSegmentWithTitle:#"Related" atIndex:1 animated:NO];
segmentedControl.selectedSegmentIndex = 0;
segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
[segmentedControl addTarget:self action:#selector(segmentedAction:) forControlEvents:UIControlEventValueChanged];
// create a standard "add" button
UIBarButtonItem* bi = [[UIBarButtonItem alloc] initWithCustomView: segmentedControl];
bi.style = UIBarButtonItemStyleBordered;
[buttons addObject:bi];
[bi release];
// create a spacer
bi = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
[buttons addObject:bi];
[bi release];
// create a standard "refresh" button
bi = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:#selector(save:)];
bi.style = UIBarButtonItemStyleBordered;
[buttons addObject:bi];
[bi release];
// stick the buttons in the toolbar
[tools setItems:buttons animated:NO];
[buttons release];
// and put the toolbar in the nav bar
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:tools];
[tools release];
Because you don't init the UIView the right way, it crashes because the iPhone doesn't know what to do with
[v insertSubview:listingsLabel atIndex:0];
This is because v isn't an object yet. So change
UIView *v;
to
UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 29)];
And release it here again (if not using arc)
self.navigationItem.titleView = v;
[v release];
The navigation bar on iPhone only supports only a left and right bar button item, and a title view. Only the (larger) navigation bar on iPad allows an arbitrary number of buttons.
If you're using a navigation bar without a navigation controller, I suppose you could just plop whatever you want onto it as subviews.
UIButton *btnBack = [[UIButton alloc]initWithFrame:CGRectMake(5,5,60,32)];
[btnBack setBackgroundImage:[UIImage imageNamed:#"back_btn.png"] forState:UIControlStateNormal];
btnBack.backgroundColor = [UIColor clearColor];
[btnBack addTarget:self action:#selector(eventBack:) forControlEvents:UIControlEventTouchUpInside];
UILabel *lbl = [[UILabel alloc]initWithFrame:CGRectMake(12, 2, 60,25)];
[lbl setBackgroundColor:[UIColor clearColor]];
lbl.font = [UIFont fontWithName:#"Helvetica" size:12];
lbl.font = [UIFont boldSystemFontOfSize:12];
lbl.textColor = [UIColor whiteColor];
lbl.text =#" Back";
[btnBack addSubview:lbl];
[lbl release];
UIBarButtonItem *backBarBtn = [[UIBarButtonItem alloc] initWithCustomView:btnBack];
self.navigationItem.leftBarButtonItem = backBarBtn;
[btnBack release];
[backBarBtn release];
UILabel *lblTitle = [[UILabel alloc] initWithFrame:CGRectMake(110, 0, 170, 40)];
lblTitle.text = #"ABC";
lblTitle.backgroundColor = [UIColor clearColor];
lblTitle.textColor = [UIColor whiteColor];
lblTitle.textAlignment = UITextAlignmentCenter;
lblTitle.font = [UIFont fontWithName:#"Helvetica" size:17];
lblTitle.font = [UIFont boldSystemFontOfSize:17];
self.navigationItem.titleView = lblTitle;
[lblTitle release];
I'm having a problem with some code in the loadView: method of one of my view controllers. Essentially I have a view which centres itself in a larger view (on an iPad) and has some labels, buttons and icons which are programmatically loaded into it.
The problem occurs when the view controller calls the dealloc method, and tries to release. I get a -[CALayer release]: message sent to deallocated instance error and the application crashes.
From reading up about this error, it appears I am over-releasing something, but I don't think that's the case: the code below is the trouble maker and I've tried both autorelease and manual release calls on everything, as well as simply not releasing them (I know, I know, that's bad) but it continues to cause havok.
container = [[UIView alloc] initWithFrame:CGRectNull];
container.autoresizingMask = ( UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin );
container.frame = CGRectMake( (viewSize.width-320)/2, (viewSize.height-480)/2, 320, 480);
[self.view addSubview:container];
UILabel *welcomeTo = [[[UILabel alloc] initWithFrame:CGRectNull] autorelease];
welcomeTo.backgroundColor = [UIColor clearColor];
welcomeTo.font = [UIFont fontWithName:#"HelveticaNeue-Light" size:18.0];
welcomeTo.frame = CGRectMake(23, 15, 103, 24);
welcomeTo.shadowColor = [UIColor blackColor];
welcomeTo.shadowOffset = CGSizeMake( 0, 1 );
welcomeTo.text = #"Welcome to";
welcomeTo.textAlignment = UITextAlignmentLeft;
welcomeTo.textColor = [UIColor colorWithWhite:1.0 alpha:0.6];
[container addSubview:welcomeTo];
UILabel *progressions = [[[UILabel alloc] initWithFrame:CGRectNull] autorelease];
progressions.backgroundColor = [UIColor clearColor];
progressions.font = [UIFont fontWithName:#"HelveticaNeue-BoldItalic" size:44.0];
progressions.frame = CGRectMake(20, 30, 280, 56);
progressions.shadowColor = [UIColor blackColor];
progressions.shadowOffset = CGSizeMake( 0, 1 );
progressions.text = #"Progressions";
progressions.textAlignment = UITextAlignmentCenter;
progressions.textColor = [UIColor colorWithWhite:1.0 alpha:0.6];
[container addSubview:progressions];
UILabel *blurb = [[[UILabel alloc] initWithFrame:CGRectNull] autorelease];
blurb.backgroundColor = [UIColor clearColor];
blurb.font = [UIFont fontWithName:#"HelveticaNeue" size:14.0];
blurb.frame = CGRectMake(23, 100, 274, 51);
blurb.numberOfLines = 3;
blurb.shadowColor = [UIColor blackColor];
blurb.shadowOffset = CGSizeMake( 0, 1 );
blurb.text = #"Kick off the fun by adding some content, or if you're not sure what you're doing, check out the \"Getting Started\" guide!";
blurb.textAlignment = UITextAlignmentLeft;
blurb.textColor = [UIColor colorWithWhite:1.0 alpha:0.6];
[container addSubview:blurb];
UIButton *button1 = [[UIButton alloc] initWithFrame:CGRectMake(20, 170, 280, 88)];
[button1 setBackgroundImage:[UIImage imageNamed:#"emptyButtonLarge.png"] forState:UIControlStateNormal];
[button1 setBackgroundImage:[UIImage imageNamed:#"emptyButtonLargeHighlighted.png"] forState:UIControlStateHighlighted];
[button1 addTarget:self action:#selector(createChart:) forControlEvents:UIControlEventTouchUpInside];
[container addSubview:button1];
[button1 release];
UIImageView *icon1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"addchart.png"]];
icon1.frame = CGRectMake(30, 180, icon1.frame.size.width, icon1.frame.size.height);
[container addSubview:icon1];
[icon1 release];
UILabel *button1title = [[[UILabel alloc] initWithFrame:CGRectMake(110, 185, 180, 20)] autorelease];
button1title.backgroundColor = [UIColor clearColor];
button1title.font = [UIFont boldSystemFontOfSize:17.0];
button1title.shadowColor = [UIColor blackColor];
button1title.shadowOffset = CGSizeMake( 0, 1 );
button1title.text = #"Create a Chart";
button1title.textAlignment = UITextAlignmentLeft;
button1title.textColor = [UIColor colorWithWhite:1.0 alpha:0.6];
[container addSubview:button1title];
UILabel *button1blurb = [[[UILabel alloc] initWithFrame:CGRectMake(110, 205, 180, 40)] autorelease];
button1blurb.backgroundColor = [UIColor clearColor];
button1blurb.font = [UIFont systemFontOfSize:13.0];
button1blurb.numberOfLines = 2;
button1blurb.shadowColor = [UIColor blackColor];
button1blurb.shadowOffset = CGSizeMake( 0, 1 );
button1blurb.text = #"A cheat sheet for a displaying a song in any key.";
button1blurb.textAlignment = UITextAlignmentLeft;
button1blurb.textColor = [UIColor colorWithWhite:1.0 alpha:0.6];
[container addSubview:button1blurb];
UIButton *button2 = [[UIButton alloc] initWithFrame:CGRectMake(20, 270, 280, 88)];
[button2 setBackgroundImage:[UIImage imageNamed:#"emptyButtonLarge.png"] forState:UIControlStateNormal];
[button2 setBackgroundImage:[UIImage imageNamed:#"emptyButtonLargeHighlighted.png"] forState:UIControlStateHighlighted];
[button2 addTarget:self action:#selector(createSet:) forControlEvents:UIControlEventTouchUpInside];
[container addSubview:button2];
[button2 release];
UIImageView *icon2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"addset.png"]];
icon2.frame = CGRectMake(30, 280, icon2.frame.size.width, icon2.frame.size.height);
[container addSubview:icon2];
[icon2 release];
UILabel *button2title = [[[UILabel alloc] initWithFrame:CGRectMake(110, 285, 180, 20)] autorelease];
button2title.backgroundColor = [UIColor clearColor];
button2title.font = [UIFont boldSystemFontOfSize:17.0];
button2title.shadowColor = [UIColor blackColor];
button2title.shadowOffset = CGSizeMake( 0, 1 );
button2title.text = #"Create a Set";
button2title.textAlignment = UITextAlignmentLeft;
button2title.textColor = [UIColor colorWithWhite:1.0 alpha:0.6];
[container addSubview:button2title];
UILabel *button2blurb = [[[UILabel alloc] initWithFrame:CGRectMake(110, 305, 180, 40)] autorelease];
button2blurb.backgroundColor = [UIColor clearColor];
button2blurb.font = [UIFont systemFontOfSize:13.0];
button2blurb.numberOfLines = 2;
button2blurb.shadowColor = [UIColor blackColor];
button2blurb.shadowOffset = CGSizeMake( 0, 1 );
button2blurb.text = #"A collection of charts that can be displayed like a book.";
button2blurb.textAlignment = UITextAlignmentLeft;
button2blurb.textColor = [UIColor colorWithWhite:1.0 alpha:0.6];
[container addSubview:button2blurb];
UIButton *button3 = [[UIButton alloc] initWithFrame:CGRectMake(20, 370, 280, 40)];
[button3 setBackgroundImage:[UIImage imageNamed:#"emptyButtonSmall.png"] forState:UIControlStateNormal];
[button3 setBackgroundImage:[UIImage imageNamed:#"emptyButtonSmallHighlighted.png"] forState:UIControlStateHighlighted];
[button3 addTarget:self action:#selector(gettingStarted:) forControlEvents:UIControlEventTouchUpInside];
[container addSubview:button3];
[button3 release];
UILabel *button3title = [[[UILabel alloc] initWithFrame:CGRectMake(20, 370, 280, 36)] autorelease];
button3title.backgroundColor = [UIColor clearColor];
button3title.font = [UIFont boldSystemFontOfSize:17.0];
button3title.shadowColor = [UIColor blackColor];
button3title.shadowOffset = CGSizeMake( 0, 1 );
button3title.text = #"Getting Started";
button3title.textAlignment = UITextAlignmentCenter;
button3title.textColor = [UIColor colorWithWhite:1.0 alpha:0.6];
[container addSubview:button3title];
UILabel *version = [[[UILabel alloc] initWithFrame:CGRectMake(20, 420, 280, 20)] autorelease];
version.backgroundColor = [UIColor clearColor];
version.font = [UIFont fontWithName:#"HelveticaNeue-Light" size:12.0];
version.shadowColor = [UIColor blackColor];
version.shadowOffset = CGSizeMake( 0, 1 );
version.text = [NSString stringWithFormat:#"Version v%# (%#)", [[[NSBundle mainBundle] infoDictionary] objectForKey:#"CFBundleVersion"], kRevisionNumber];
version.textAlignment = UITextAlignmentCenter;
version.textColor = [UIColor colorWithWhite:1.0 alpha:0.6];
[container addSubview:version];
The container property is released in the dealloc method, as follows:
- (void)dealloc {
[leather release];
[backButton release];
[container release];
[super dealloc];
}
Any answers or suggestions people can provide would be greatly appreciated! I am truly stumped.
Profile your application in the simulator with 'Zombies' Instrument.
Run your app for a while and do whatever you have to do to make your app crash. When it does, you will get a pop up like the image below and it will halt the profiling of the app:
Then if you click on the little arrow next to the address (0x158b3c00) .. it will take you to the object retain/release history for the object that was over released (the zombie).
If you highlight the line above where the retain count went to -1, and open View -> Extended detail, it should point you to the stack trace and line in your code where the object was overreleased:
If you double click the class where it is occuring, it will open up your source and show you the bad line of code:
The over-releasing could be occurring during the objects life time and not just when they're being created. A few tips:
use accessors to ensure that pointers are set to nil
be consistent with your use of release/autorelease. Personally I prefer to have [[[Class alloc] init] autorelease] all on 1 line.
Learn the difference between release/autorelease. Let's Build NSAutoreleasePool is a good place to start.