ChildViewController not able to modify its UI after creation - ios

I have a view controller which is being added as a child view controller. The problem is that after the child controller creates its view, I am not able to modify it.
It loads everything properly, but when I want to hide a text field on clicking a button (textfield.hidden = YES), nothing happens!
This is my loadView :
-(void)loadView {
self.waitingPopup = [[WaitingPopupViewController alloc]initWithLabel:#"loading salon"];
self.view=[[UIView alloc] initWithFrame:[UIScreen mainScreen].applicationFrame];
// self.view.frame=CGRectMake(0, -20, self.view.frame.size.width, self.view.frame.size.height);
scrollableTable=[[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
scrollableTable.delegate=self;
scrollableTable.dataSource=self;
[self.view addSubview:scrollableTable];
headerHolder=[[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height-44)];
//creating and adding backgroundImage view container and setting the image
// saloonHomeImage.backgroundColor = [UIColor grayColor];
saloonHomeImage.frame=CGRectMake(self.view.frame.origin.x, 0, self.view.frame.size.width, self.view.frame.size.height);
saloonHomeImage.contentMode = UIViewContentModeScaleAspectFill;
//[saloonHomeImage setBackgroundColor:[UIColor redColor]];
[headerHolder setBackgroundColor:[UIColor grayColor]];
[headerHolder addSubview:saloonHomeImage];
//creating and adding saloonheader label
saloonLabel=[[UILabel alloc] initWithFrame:CGRectMake(0, 32, self.view.frame.size.width, 48)];
saloonLabel.text=#"";
saloonLabel.textAlignment=NSTextAlignmentCenter;
[saloonLabel setTextColor:[UIColor whiteColor]];
[saloonLabel setFont:[UIFont fontWithName:#"vevey" size:48]];
[headerHolder addSubview:saloonLabel];
//creating and adding book appointment button
UIButton *bookAppointmentButton=[UIButton buttonWithType:UIButtonTypeSystem];
NSLog(#"%f", self.view.frame.size.height-97.5);
bookAppointmentButton.frame=CGRectMake(self.view.frame.origin.x, self.view.frame.size.height-97.5, 216, 53);
[bookAppointmentButton setBackgroundImage:[UIImage imageNamed:#"bg-left.png"] forState:UIControlStateNormal];
[bookAppointmentButton setTitle:#"BOOK APPOINTMENT" forState:UIControlStateNormal];
[bookAppointmentButton addTarget:self action:#selector(bookAppointmentAction) forControlEvents:UIControlEventTouchUpInside];
[bookAppointmentButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
[headerHolder addSubview:bookAppointmentButton];
UIButton *callButton=[UIButton buttonWithType:UIButtonTypeSystem];
callButton.frame=CGRectMake(216, self.view.frame.size.height-97.5, self.view.frame.size.width-216, 53);
[callButton setBackgroundImage:[UIImage imageNamed:#"bg-right.png"] forState:UIControlStateNormal];
[callButton addTarget:self action:#selector(callButtonAction) forControlEvents:UIControlEventTouchUpInside];
[callButton setTitle:#"CALL" forState:UIControlStateNormal];
[callButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
[headerHolder addSubview:callButton];
[self getSalonDetails];
loading=[[UIImageView alloc] init];
loading.frame=CGRectMake(130,200,40,36);
[loading setBackgroundColor:[UIColor clearColor]];
loading.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:#"spinner-1.png"],
[UIImage imageNamed:#"spinner-2.png"],
[UIImage imageNamed:#"spinner-3.png"],
[UIImage imageNamed:#"spinner-4.png"],
[UIImage imageNamed:#"spinner-5.png"],
[UIImage imageNamed:#"spinner-6.png"],
[UIImage imageNamed:#"spinner-7.png"],
[UIImage imageNamed:#"spinner-8.png"],[UIImage imageNamed:#"spinner-9.png"],nil];
loading.animationDuration = 1.0f;
loading.animationRepeatCount = 0;
[loading startAnimating];
[self.view addSubview:loading];
loadingText = [[UILabel alloc]initWithFrame:CGRectMake(90, 240, 200, 40)];
loadingText.text = #"loading salon";
[loadingText setFont:GOTHIC_FONT(22)];
[loadingText setTextColor:[UIColor whiteColor]];
[self.view addSubview:loadingText];
articles=[Model getArticles];
}
- (void) getSalonDetails{
[[MyDataModel sharedDataModel] getSalonDetails];
}
This is the delegate method which is trying to set some fields hidden. This delegate is called when an NSURLSession call completes successfully. The control comes here as per logs but nothing gets hidden. When I add a breakpoint and inspect the fields, every object is shown as nil. If this class is used as the main view controller, I've found everything works. On making it a child view, nothing works.
-(void)salonDetailsRecievedDelegate:(BOOL)success andStatusCode:(int)statusCode{
[loading stopAnimating];
self.loading.hidden = YES;
self.loadingText.hidden = YES;
saloonLabel.text = #"this is texT";
if(success){
//
}
}

What I think here is that salonDetailsRecievedDelegate isn't called from the main thread, try any of the following:
1) call it in the main thread from your model as follows:
dispatch_async(dispatch_get_main_queue(), ^{
[self.delegate salonDetailsRecievedDelegate:success andStatusCode:status];
});
2) change its implementation as follows:
-(void)salonDetailsRecievedDelegate:(BOOL)success andStatusCode:(int)statusCode{
dispatch_async(dispatch_get_main_queue(), ^{
[loading stopAnimating];
self.loading.hidden = YES;
self.loadingText.hidden = YES;
saloonLabel.text = #"this is texT";
if(success){
//
}
});
}

Related

Issues in scroll view

Actually There are four buttons and there is sub buttons for each button.once I click first button the second button have to move down by giving space for sub buttons but its not working even after setting scroll view.
bgsroll=[[UIScrollView alloc]init];
bgsroll.frame=CGRectMake(0, 0, CGRectGetWidth(self.view.frame), CGRectGetHeight(self.view.frame));
bgsroll.userInteractionEnabled=YES;
bgsroll.scrollEnabled=YES;
// bgsroll.backgroundColor=[UIColor grayColor];
bgsroll.showsVerticalScrollIndicator=YES;
bgsroll.contentSize=CGSizeMake(200, 2000);
[self.view addSubview:bgsroll];
happyBtn=[[UIButton alloc]init];
happyBtn.frame=CGRectMake(MainView.frame.size.width*0.12, MainView.frame.size.height*0.1, CGRectGetWidth(self.view.frame)/1.5, 40);
[happyBtn setTitle:#"Happiness" forState:UIControlStateNormal];
[happyBtn setBackgroundColor:[UIColor colorWithRed:0.400f green:0.737f blue:0.761f alpha:1.00f]];
[happyBtn addTarget:self action:#selector(tapHappy:) forControlEvents:UIControlEventTouchUpInside];
[bgsroll addSubview:happyBtn];
happyView=[[UIView alloc]init];
happyView.frame=CGRectMake(MainView.frame.size.width*0.26,CGRectGetHeight(happyBtn.frame)*2.2, CGRectGetWidth(MainView.frame)/1.6, CGRectGetHeight(MainView.frame)/3);
happyView.layer.cornerRadius=8.0;
happyView.layer.borderWidth=0.5;
happyView.layer.borderColor=[[UIColor blueColor]CGColor];
[bgsroll addSubview:happyView];
LettingGo=[[UIButton alloc]init];
LettingGo.frame=CGRectMake(happyView.frame.size.width*0.01,happyView.frame.size.height*0.1, CGRectGetWidth(happyView.frame)/1.05, 50);
[LettingGo setTitle:#"Letting go of negativity" forState:UIControlStateNormal];
LettingGo.titleLabel.numberOfLines=2;
LettingGo.titleLabel.adjustsFontSizeToFitWidth=YES;
[LettingGo setBackgroundColor:[UIColor colorWithRed:0.400f green:0.737f blue:0.761f alpha:1.00f]];
[happyView addSubview:LettingGo];
LivingPresent=[[UIButton alloc]init];
LivingPresent.frame=CGRectMake(happyView.frame.size.width*0.01,LettingGo.frame.size.height*1.4, CGRectGetWidth(happyView.frame)/1.05, 40);
[LivingPresent setTitle:#"Living in the present" forState:UIControlStateNormal];
LivingPresent.titleLabel.adjustsFontSizeToFitWidth=YES;
[LivingPresent setBackgroundColor:[UIColor colorWithRed:0.400f green:0.737f blue:0.761f alpha:1.00f]];
[happyView addSubview:LivingPresent];
happyView.hidden=YES;
CreateBtn=[[UIButton alloc]init];
CreateBtn.frame=CGRectMake(MainView.frame.size.width*0.12, MainView.frame.size.height*0.5, CGRectGetWidth(self.view.frame)/1.5, 40);
[CreateBtn setTitle:#"Happiness" forState:UIControlStateNormal];
[CreateBtn setBackgroundColor:[UIColor colorWithRed:0.400f green:0.737f blue:0.761f alpha:1.00f]];
[CreateBtn addTarget:self action:#selector(tapHappy:) forControlEvents:UIControlEventTouchUpInside];
[bgsroll addSubview:CreateBtn];
-(void)tapHappy:(id)selector{
happyView.hidden=!happyView.hidden;
}
By not working you mean it is not scrolling when the buttons are pushed? I find it easier to scroll elements creating a method that changes the coordinates of elements in subviews through animations. Something like this:
- (void)viewDidLoad {
expandButton1 = [UIButton buttonWithType:UIButtonTypeCustom];
[expandButton1 addTarget:self action:#selector(expandButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
}
- (void)expandButtonPressed:(id)sender{
if (expanded == NO) {
expanded = YES;
[UIView animateWithDuration:0.5 delay:0.0 options:UIViewAnimationOptionRepeat animations:^{
[UIView setAnimationRepeatCount:1];
image1.frame = CGRectMake(image1.frame.origin.x, image1.frame.origin.y+200.0f, image1.frame.size.width, image1.frame.size.height);
image.frame2 = CGRectMake(image2.frame.origin.x, image2.frame.origin.y+200.0f, image2.frame.size.width, image2.frame.size.height);
expandButton2.frame = CGRectMake(expandButton2.frame.origin.x, expandButton2.frame.origin.y+200.0f, expandButton2.frame.size.width, expandButton2.frame.size.height);
expandButton3.frame = CGRectMake(expandButton3.frame.origin.x, expandButton3.frame.origin.y+200.0f, expandButton3.frame.size.width, expandButton3.frame.size.height);
}completion:nil];
}

didTapInfoWindowOfMarker multiple buttons click event info

I am displaying some map points in google map. when user will click on that map point. I markerInfoWindow will be display. In this window, I am using two buttons. whenever user will click on that buttons. didTapInfoWindowOfMarker fires. but i amn't able to identify that which one has been clicked. may you please help me for that? i don't want to use any other approach.
Thanks
update:- This is infoWindow code.
-(void)prepareBubble
{
// UIView *bubble = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 80)];
self .frame = CGRectMake(0, 0, 260, 130);
self.backgroundColor = [UIColor clearColor];
// self.layer.borderColor = [UIColor grayColor].CGColor;
// self.layer.borderWidth = 1;
// self.layer.cornerRadius = 7;
UIImageView *bg = [[UIImageView alloc] initWithFrame:self.frame];
bg.image = [UIImage imageNamed:#"popup.png"];
[self addSubview:bg];
self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(90, 5, 150, 40)];
self.titleLabel.backgroundColor = [UIColor clearColor];
[self.titleLabel setAdjustsFontSizeToFitWidth:TRUE];
self.titleLabel.numberOfLines = 0;
self.titleLabel.font = [UIFont fontWithName:FontNameArialBold size:14];
self.titleLabel.text = _title;
self.addressLabel= [[UILabel alloc] initWithFrame:CGRectMake(90, 40, 150, 35)];
self.addressLabel.backgroundColor = [UIColor clearColor];
[self.addressLabel setAdjustsFontSizeToFitWidth:TRUE];
self.addressLabel.numberOfLines = 0;
self.addressLabel.font = [UIFont fontWithName:FontNameArial size:12];
self.addressLabel.text = _address;
self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(15, 15, 70, 70)];
[self addSubview:self.imageView];
self.imageView.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:_imageUrl]]];
if ( self.imageView.image == nil )
{
self.imageView.image = [UIImage imageNamed:DefaultImage100];
}
// [[[CustomNetwork alloc] init] setImage:_imageUrl onImageView:self.imageView withPlaceHolderImage:DefaultImage100];
[self addSubview:self.titleLabel];
[self addSubview:self.addressLabel];
if ( _ratings > 0 )
{
[self addSubview:[self addStar:_ratings]];
}
if( _hasTeeTimes ) {
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button setTitle:#"Book" forState:UIControlStateNormal];
[button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
UIImage *buttonImage = [UIImage imageNamed:#"button_orange_large.png"];
[button setBackgroundImage:buttonImage forState:UIControlStateNormal];
button.frame = CGRectMake(200, 75, 45, 25);
[self addSubview:button];
}
// return self;
}
here I am trying to make to click listener, first is on button and another is on tap in any part of this window like as textField etc. so my two new view will push
Change the buttons to properties.
Give the buttons tags.
Logically
determine by identifying the sender and see if it is > or < the other
button (which you need to keep in memory by making them properties or
instance variables).
load custom Xibs, and all of these will work with 0 lines of code.

Custom navigation bar back button hit area

I have implement custom back Navigation bar button.
Codes:
-(UIBarButtonItem*) logicToAddBackButton {
UIImageView *imageView=[[UIImageView alloc] initWithImage:[UIImage imageNamed:#"UiNavigationBack"]];
UILabel *label=[[UILabel alloc] init];
[label setTextColor:[UIColor colorWithRed:0.0 green:122.0/255.0 blue:1.0 alpha:1.0]];
[label setText:#"Home"];
[label sizeToFit];
int space=6;
label.frame=CGRectMake(imageView.frame.origin.x+imageView.frame.size.width+space, label.frame.origin.y, label.frame.size.width, label.frame.size.height);
UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, 0, label.frame.size.width+imageView.frame.size.width+space, imageView.frame.size.height)];
view.bounds=CGRectMake(view.bounds.origin.x+8, view.bounds.origin.y-1, view.bounds.size.width, view.bounds.size.height);
[view addSubview:imageView];
[view addSubview:label];
UIButton *button=[[UIButton alloc] initWithFrame:view.frame];
[button addTarget:self action:#selector(eventBack) forControlEvents:UIControlEventTouchUpInside];
[view addSubview:button];
[UIView animateWithDuration:0.33 delay:0 options:UIViewAnimationOptionCurveLinear animations:^{
label.alpha = 0.0;
CGRect orig=label.frame;
label.frame=CGRectMake(label.frame.origin.x+25, label.frame.origin.y, label.frame.size.width, label.frame.size.height);
label.alpha = 1.0;
label.frame=orig;
} completion:nil];
UIBarButtonItem *backButton =[[UIBarButtonItem alloc] initWithCustomView:view];
return backButton;
}
self.navigationItem.leftBarButtonItem = [self logicToAddBackButton];
This is how it look and work fine according to the logic.
Issue: If we click on first half of arrow, the back button do not respond.
Please suggest on this.
Try to set to your button:
button.contentEdgeInsets = UIEdgeInsetsMake(<#CGFloat top#>, <#CGFloat left#>, <#CGFloat bottom#>, <#CGFloat right#>)
I think you miscalculating frame somewhere.
Why don't you add UIButton instead? It will be much easier, but without label animation.
UIButton *button = [[UIButton alloc] init];
[button addTarget:self action:#selector(eventBack:) forControlEvents:UIControlEventTouchUpInside];
[button setTitle:#"Home" forState:UIControlStateNormal];
[button setImage:[UIImage imageNamed:#"UiNavigationBack"] forState:UIControlStateNormal];
[button setTitleColor:[UIColor colorWithRed:0.0 green:122.0/255.0 blue:1.0 alpha:1.0] forState:UIControlStateNormal];
[button sizeToFit];
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithCustomView:button];
return backButton;

iOS share comman view on diffrent view controller

I have implemented sliding menu code in iOS and want to share that single code for all view controller. is it possible ?? if yes then how can i implement this in my project ?
Can anyone help me for this ?
Here is a code I written in a view controller, and I want to share this code for all view controller.
(void)initslidingcode
{
//selected button background
_selectedbtnback=[[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Menu_selection.png"]];
//end
//sliding code
slidestatus=0;
_menu=[[UIView alloc]initWithFrame:CGRectMake(-190,60,190,450)];
UIImageView *back=[[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Menu_Bg.png"]];
back.frame=CGRectMake(0,-20,220,450);
[_menu insertSubview:back atIndex:0];
_menu.userInteractionEnabled=NO;
[_leftmenu setTarget:self];
[_leftmenu setAction:#selector(showmenu)];
UIImageView *img=[[UIImageView alloc] initWithFrame:CGRectMake(45,7,80,80)];
img.image=[UIImage imageNamed:#"profile.jpg"];
img.layer.cornerRadius=img.frame.size.width/2;
img.clipsToBounds=YES;
img.layer.borderWidth = 1.0f;
img.layer.borderColor = [UIColor greenColor].CGColor;
[_menu addSubview:img];
UILabel *username=[[UILabel alloc] initWithFrame:CGRectMake(0,88,175,18)];
username.text=#"Dilip Ingole";
username.textColor=[UIColor whiteColor];
username.textAlignment=NSTextAlignmentCenter;
[_menu addSubview:username];
UIImageView *line=[[UIImageView alloc] initWithFrame:CGRectMake(0,105,180,15)];
line.image=[UIImage imageNamed:#"menu_divided_line.png"];
[_menu addSubview:line];
_activitybtn=[[UIButton alloc] initWithFrame:CGRectMake(0,110,180,37)];
_inboxbtn=[[UIButton alloc] initWithFrame:CGRectMake(0,150,180,37)];
_nutritionchartbtn=[[UIButton alloc] initWithFrame:CGRectMake(0,190,180,37)];
_trainingplanbtn=[[UIButton alloc] initWithFrame:CGRectMake(0,230,180,37)];
_heartbeatbtn=[[UIButton alloc] initWithFrame:CGRectMake(0,270,180,37)];
_friends=[[UIButton alloc] initWithFrame:CGRectMake(0,310,180,37)];
_goalsbtn=[[UIButton alloc] initWithFrame:CGRectMake(0,350,180,37)];
_goshopbtn=[[UIButton alloc] initWithFrame:CGRectMake(0,390,180,37)];
[_activitybtn setTitle:#"Activity" forState:UIControlStateNormal];
_activitybtn.contentHorizontalAlignment=UIControlContentHorizontalAlignmentLeft;
[_activitybtn setImage:[UIImage imageNamed:#"Menu_selection.png"] forState:UIControlStateHighlighted];
[_activitybtn addTarget:self action:#selector(openactivity) forControlEvents:UIControlEventTouchUpInside];
img=[[UIImageView alloc] initWithFrame:CGRectMake(2, 1, 40, 40)];
img.image=[UIImage imageNamed:#"Activity_icon.png"];
_activitybtn.titleEdgeInsets = UIEdgeInsetsMake(0, 50, 0,0);
[_activitybtn addSubview:img];
[_menu addSubview:_activitybtn];
UIImageView *line1=[[UIImageView alloc] initWithFrame:CGRectMake(0,145,180,15)];
line1.image=[UIImage imageNamed:#"menu_divided_line.png"];
[_menu addSubview:line1];
[_inboxbtn setTitle:#"Inbox" forState:UIControlStateNormal];
[_inboxbtn.titleLabel setTextAlignment:NSTextAlignmentLeft];
[_inboxbtn setImage:[UIImage imageNamed:#"Menu_selection.png"] forState:UIControlStateHighlighted];
[_inboxbtn addTarget:self action:#selector(openinbox) forControlEvents:UIControlEventTouchUpInside];
img=[[UIImageView alloc] initWithFrame:CGRectMake(2, 1, 40, 40)];
img.image=[UIImage imageNamed:#"Msgbox_icon.png"];
_inboxbtn.titleEdgeInsets = UIEdgeInsetsMake(0,0,0,30);
[_inboxbtn addSubview:img];
[_menu addSubview:_inboxbtn];
UIImageView *line2=[[UIImageView alloc] initWithFrame:CGRectMake(0,183,180,15)];
line2.image=[UIImage imageNamed:#"menu_divided_line.png"];
[_menu addSubview:line2];
[_nutritionchartbtn setTitle:#"Nutrition Chart" forState:UIControlStateNormal];
[_nutritionchartbtn.titleLabel setTextAlignment:NSTextAlignmentLeft];
[_nutritionchartbtn setImage:[UIImage imageNamed:#"Menu_selection.png"] forState:UIControlStateHighlighted];
[_nutritionchartbtn addTarget:self action:#selector(opennutritionchart) forControlEvents:UIControlEventTouchUpInside];
img=[[UIImageView alloc] initWithFrame:CGRectMake(2, 1, 40, 40)];
img.image=[UIImage imageNamed:#"Nutrition_Icon.png"];
_nutritionchartbtn.titleEdgeInsets = UIEdgeInsetsMake(0,45, 0,0);
[_nutritionchartbtn addSubview:img];
[_menu addSubview:_nutritionchartbtn];
UIImageView *line3=[[UIImageView alloc] initWithFrame:CGRectMake(0,223,180,15)];
line3.image=[UIImage imageNamed:#"menu_divided_line.png"];
[_menu addSubview:line3];
[_trainingplanbtn setTitle:#"Training Plan" forState:UIControlStateNormal];
[_trainingplanbtn setImage:[UIImage imageNamed:#"Menu_selection.png"] forState:UIControlStateHighlighted];
[_trainingplanbtn addTarget:self action:#selector(opentrainingplan) forControlEvents:UIControlEventTouchUpInside];
img=[[UIImageView alloc] initWithFrame:CGRectMake(2, 1, 40, 40)];
img.image=[UIImage imageNamed:#"Training_icon.png"];
_trainingplanbtn.titleEdgeInsets = UIEdgeInsetsMake(0, 30, 0,0);
[_trainingplanbtn addSubview:img];
[_menu addSubview:_trainingplanbtn];
UIImageView *line4=[[UIImageView alloc] initWithFrame:CGRectMake(0,263,180,15)];
line4.image=[UIImage imageNamed:#"menu_divided_line.png"];
[_menu addSubview:line4];
[_heartbeatbtn setTitle:#"Heart Beat" forState:UIControlStateNormal];
[_heartbeatbtn setImage:[UIImage imageNamed:#"Menu_selection.png"] forState:UIControlStateHighlighted];
[_heartbeatbtn addTarget:self action:#selector(openheartbeat) forControlEvents:UIControlEventTouchUpInside];
img=[[UIImageView alloc] initWithFrame:CGRectMake(2, 1, 40, 40)];
img.image=[UIImage imageNamed:#"heart_icon.png"];
_heartbeatbtn.titleEdgeInsets = UIEdgeInsetsMake(0,20, 0,0);
[_heartbeatbtn addSubview:img];
[_menu addSubview:_heartbeatbtn];
UIImageView *line5=[[UIImageView alloc] initWithFrame:CGRectMake(0,303,180,15)];
line5.image=[UIImage imageNamed:#"menu_divided_line.png"];
[_menu addSubview:line5];
[_friends setTitle:#"Friends" forState:UIControlStateNormal];
[_friends setImage:[UIImage imageNamed:#"Menu_selection.png"] forState:UIControlStateHighlighted];
[_friends addTarget:self action:#selector(openfriends) forControlEvents:UIControlEventTouchUpInside];
img=[[UIImageView alloc] initWithFrame:CGRectMake(2, 1, 40, 40)];
img.image=[UIImage imageNamed:#"Friends_icon.png"];
_friends.titleEdgeInsets = UIEdgeInsetsMake(0,0, 0,5);
[_friends addSubview:img];
[_menu addSubview:_friends];
UIImageView *line6=[[UIImageView alloc] initWithFrame:CGRectMake(0,343,180,15)];
line6.image=[UIImage imageNamed:#"menu_divided_line.png"];
[_menu addSubview:line6];
[_goalsbtn setTitle:#"Goals" forState:UIControlStateNormal];
[_goalsbtn setImage:[UIImage imageNamed:#"Menu_selection.png"] forState:UIControlStateHighlighted];
[_goalsbtn addTarget:self action:#selector(opengoals) forControlEvents:UIControlEventTouchUpInside];
img=[[UIImageView alloc] initWithFrame:CGRectMake(2, 1, 40, 40)];
img.image=[UIImage imageNamed:#"Goals_icon.png"];
_goalsbtn.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0,25);
[_goalsbtn addSubview:img];
[_menu addSubview:_goalsbtn];
UIImageView *line7=[[UIImageView alloc] initWithFrame:CGRectMake(0,383,180,15)];
line7.image=[UIImage imageNamed:#"menu_divided_line.png"];
[_menu addSubview:line7];
[_goshopbtn setTitle:#"Go Shop" forState:UIControlStateNormal];
[_goshopbtn setImage:[UIImage imageNamed:#"Menu_selection.png"] forState:UIControlStateHighlighted];
[_goshopbtn addTarget:self action:#selector(opengoshop) forControlEvents:UIControlEventTouchUpInside];
img=[[UIImageView alloc] initWithFrame:CGRectMake(2, 1, 40, 40)];
img.image=[UIImage imageNamed:#"Shoping Icon.png"];
_goshopbtn.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0,0);
[_goshopbtn addSubview:img];
[_menu addSubview:_goshopbtn];
//sliding
}
-(void)showmenu
{
[_menu removeFromSuperview];
_menu.userInteractionEnabled=YES;
if (slidestatus==0)
{
slidestatus=1;
[UIView animateWithDuration:0.5f animations:^{
_menu.frame = CGRectMake(0,60,190,450);
}];
}
else
{
slidestatus=0;
[UIView animateWithDuration:0.5f animations:^{
_menu.frame = CGRectMake(-190,60,190,450);
}];
}
[self.view insertSubview:_menu atIndex:100];
}
-(void)openactivity
{
//open activity controller
}
-(void)openinbox
{
[_inboxbtn setImage:[UIImage imageNamed:#"Menu_selection.png"] forState:UIControlStateHighlighted];
//open activity controller
}
-(void)opennutritionchart
{
//open activity controller
}
-(void)opentrainingplan
{
//open activity controller
}
-(void)openheartbeat
{
//open activity controller
NSLog(#"heart controller");
}
-(void)openfriends
{
//open activity controller
}
-(void)opengoals
{
//open activity controller
}
-(void)opengoshop
{
//open activity controller
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
slidestatus=0;
[UIView animateWithDuration:0.5f animations:^{
_menu.frame = CGRectMake(-190,60,190,450);
}];
}
This guys did wonderful job with side menu.
There is also integrations instructions.
MVYSideMenu
Anyway, To achieve your task, consider to manage your side menu from the AppDelegate and consider to add the side menu on top of the appDelegate.window same as UITabBarController, for example.

Custom UIButton not working

After looking through the post on this simple topic I still can not figure out what I've done wrong here. I am trying to make the buttons loop through the same action in the same viewController.
When the view comes onto the screen the buttons do not click (or at least the NSLog does not write to the console which it does the first time it enters this code.)
- (IBAction)answer: (id) sender{
NSLog(#"The Number is: %d\n",qNumber);
qNumber+=1;
UIView *newView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
[newView setUserInteractionEnabled:TRUE];
UIImage *buttonImage = [UIImage imageNamed:#"pink_button.png"];
UIImageView *buttonImageView = [[[UIImageView alloc] initWithFrame:CGRectMake(23, 294, 72, 37)] autorelease];
[buttonImageView setImage:buttonImage];
UILabel* buttonLabel = [[[UILabel alloc] initWithFrame:CGRectMake(23, 294, 72, 37)] autorelease];
buttonLabel.text = #"newLow";
buttonLabel.font = [UIFont fontWithName:#"Helvetica-Bold" size: 15.0];
buttonLabel.textColor = [UIColor blackColor];
buttonLabel.backgroundColor = [UIColor clearColor];
buttonLabel.textAlignment = UITextAlignmentCenter;
lowButton = [UIButton buttonWithType:UIButtonTypeCustom];
[lowButton addSubview:buttonImageView];
[lowButton addSubview:buttonLabel];
[lowButton addTarget:self action:#selector(answer:) forControlEvents:UIControlEventTouchUpInside];
[newView addSubview:lowButton];
self.view = newView;
}
Thanks for any help you can provide...even if I missed something simple :-)
Latest Updated Code:
lowButton = [UIButton buttonWithType:UIButtonTypeCustom];
[newView addSubview:buttonImageView];
[newView addSubview:buttonLabel];
[lowButton addTarget:self action:#selector(answer:) forControlEvents:UIControlEventTouchUpInside];
[newView addSubview:lowButton];
[self.view bringSubviewToFront:lowButton];
self.view = newView;
Still when the button is pressed it does not enter the action code.
You button needs a frame. You can't tap a frameless button.
lowButton.frame = CGRectMake(23, 294, 72, 37);
Also, when you add label and image to that button, their frame should have x and y 0.
UIImageView *buttonImageView = [[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 72, 37)] autorelease];
...
UILabel* buttonLabel = [[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 72, 37)] autorelease];
...
But may I ask why you are adding new UIImageView and UILabel to UIButton when it has it's label and background view properties?
Edit here is a cleaned-up code for you:
UIView *newView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
lowButton = [UIButton buttonWithType:UIButtonTypeCustom];
[lowButton setImage:[UIImage imageNamed:#"pink_button.png"] forState:UIControlStateNormal];
[lowButton setTitle:#"newLow" forState:UIControlStateNormal];
[lowButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[lowButton.titleLabel setFont:[UIFont boldSystemFontOfSize:15.0]];
[lowButton addTarget:self action:#selector(answer:) forControlEvents:UIControlEventTouchUpInside];
[newView addSubview:lowButton];
self.view = newView;
Notice I also removed [newView setUserInteractionEnabled:TRUE]; as it's not needed since it's enabled by default.
Your custom button's subviews are covering the button, so it does not get any clicks.
Try adding all the subviews to newView rather than to lowButton (including lowButton itself) and then call
[self.view bringSubViewToFront:lowButton];

Resources