Jssocials not working in UIWebView/WKWebView - objective-c

I want to use jssocial plugin in iOS,there is no response when user clicks on buttons be it a Facebook, twitter or Instagram from UIWebView and also not from WKWebView so, if anybody have implemented it in iOS then please guide me about it.
Any help will be appreciable. Thank You

Set WKWebView properties and delegates as follow
WKPreferences *prefs = [WKPreferences new];
prefs.javaScriptEnabled = YES;
prefs.javaScriptCanOpenWindowsAutomatically = YES;
WKWebViewConfiguration *theConfig = [[WKWebViewConfiguration alloc] init];
theConfig.preferences = prefs;
webView = [[EasyJSWKWebView alloc] initWithFrame:self.view.bounds
configuration:theConfig
withJavascriptInterfaces:interfaces];
webView.UIDelegate = self;
webView.navigationDelegate = self;
[webView setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
if (#available(iOS 11.0, *)) {
webView.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
}
[webView loadRequest:requestObj];
[self.view addSubview:webView];
- (WKWebView *)webView:(WKWebView *)webView createWebViewWithConfiguration:(WKWebViewConfiguration *)configuration forNavigationAction:(WKNavigationAction *)navigationAction windowFeatures: (WKWindowFeatures *)windowFeatures
{
ViewPopUp = [[UIView alloc] initWithFrame:self.view.frame];
[ViewPopUp setBackgroundColor:[UIColor whiteColor]];
[self.view addSubview:ViewPopUp];
UIButton *btnBack = [[UIButton alloc] initWithFrame:CGRectMake(0, 20, 50, 50)];
[btnBack setImage:[UIImage imageNamed:#"back"] forState:UIControlStateNormal];
[btnBack addTarget:self action:#selector(backButtonClicked) forControlEvents:UIControlEventTouchUpInside];
[ViewPopUp addSubview:btnBack];
PopUpView = [[WKWebView alloc] initWithFrame:CGRectMake(0, 64, self.view.frame.size.width, self.view.frame.size.height-64) configuration:configuration];
PopUpView.allowsBackForwardNavigationGestures = YES;
PopUpView.navigationDelegate = self;
[self.view addSubview:PopUpView];
return PopUpView;
}

Related

Programatically created UIDatepicke done and cancle button is not working

This is my UIDatePicker code but in that picker, done and cancle button is not working ...please help me.... i also add here my done and cancle button methods here..Please give me a proper suggessions for how it works properly.
if (textField.tag==Jobdatetxt.tag)
{
[Jobdatetxt resignFirstResponder];
[data.toolbar removeFromSuperview];
UITextField *lagFreeField = [[UITextField alloc] init];
[self.view.window addSubview:lagFreeField];
[lagFreeField becomeFirstResponder];
[lagFreeField resignFirstResponder];
[lagFreeField removeFromSuperview];
//////////////////////////////////////////////// DATE OF JOB////////////////////////////////////////////////
pickerDate = [[UIDatePicker alloc] initWithFrame:CGRectMake(0,result.height - 216, result.width, 216)];
[pickerDate setDatePickerMode:UIDatePickerModeDate];
pickerDate.backgroundColor = [UIColor whiteColor];
[self.view.window addSubview:pickerDate];
toolbar = [[UIToolbar alloc] init];
toolbar.barStyle = UIBarStyleBlackOpaque;
toolbar.frame=CGRectMake(0,result.height - 266,result.width,50);
cancel = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[cancel setTitle:#"Cancel" forState:UIControlStateNormal];
cancel.backgroundColor = [UIColor clearColor];
[cancel.titleLabel setFont:[UIFont boldSystemFontOfSize:18]];
cancel.titleLabel.textColor = [UIColor whiteColor];
[cancel addTarget:self action:#selector(CancelClicked:) forControlEvents:UIControlEventTouchUpInside];
cancel.tag = textField.tag;
cancel.frame = CGRectMake(10, 10, 70, 30);
[toolbar addSubview:cancel];
doneButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[doneButton setTitle:#"Done" forState:UIControlStateNormal];
doneButton.backgroundColor = [UIColor clearColor];
[doneButton.titleLabel setFont:[UIFont boldSystemFontOfSize:18]];
doneButton.titleLabel.textColor = [UIColor whiteColor];
[doneButton addTarget:self action:#selector(DoneClicked:) forControlEvents:UIControlEventTouchUpInside];
doneButton.tag = textField.tag;
doneButton.frame = CGRectMake(result.width - 80, 10, 70, 30);
[toolbar addSubview:doneButton];
[self.view.window addSubview:toolbar];
}
// Done Button method
-(IBAction)DoneClicked:(UIButton *)sender
{
[pickerDate removeFromSuperview];
[toolbar removeFromSuperview];
}
//Cancle Button Method
-(IBAction)CancelClicked:(UIButton *)sender
{
[pickerDate removeFromSuperview];
[toolbar removeFromSuperview];
}

ScrollsToTop is not working when UIVeiwController is presented from ios8 extension

ScrollsToTop is not working when UIVeiwController is presented from ios8 extension.
But it is working if we presented it from inside the app. Can anyone help? sample code is shared here.
UIScrollView * scrollview = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 320, 300) ];
[scrollview setContentSize:CGSizeMake(320, 800)];
scrollview.layer.borderWidth = 1.0;
scrollview.backgroundColor =[UIColor redColor];
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"slide1"]];
[scrollview addSubview:imageView];
scrollview.showsVerticalScrollIndicator =YES;
scrollview.scrollsToTop = YES;
scrollview.delegate = self;
UIViewController *a = [[UIViewController alloc] init];
a.view.backgroundColor = [UIColor greenColor];
[a.view addSubview:scrollview];
[self presentViewController:a animated:YES completion:^{
}];
I had same issues & resolved using code bellow.
Some change has done in xcode6. Try this code to make scrollview to top.
[self.ScrollView setContentOffset:CGPointMake(0.0, 0.0) animated:YES];

UITabBar customisation not working as expected

I have a three tab UITabBar in which the background of each tab is set, along with the background of the tabbar itself, as seen in the first image below. Each UITabBarItem has its FinishedSelectedImage and FinishedUnselectedImage set, and an NSString to its title. These images are glyphs (icons).
However, having set the selectionIndicatorImage to an image sized 106x48px, there is ~1px space to the right of the third tab, when in its selected state (see second photo).
Please can you tell me how I can remove the additional space? I have tried using an image sized 1px wider, but that made no difference.
Edit--- I read that this could be a problem due to an incorrectly sized selectionIndicatorImage, but I can confirm that this was not a fix -- I tried using a 107x49px image, and that too did not make a difference.
Max.
Tab Bar (how it should be upon selection)
Tab Bar (how it shows up on the third tab - notice the 1px on the right)
// customise the UITabBar - set the background image and the selected background image
[self.tabBarController.tabBar setBackgroundImage:[UIImage imageNamed:#"tab_bar"]];
[self.tabBarController.tabBar setSelectionIndicatorImage:[UIImage imageNamed:#"tabbar_selection_bg_3"]];
// this is in a for loop.
UITabBarItem *item = [[UITabBarItem alloc] init];
[item setTitle:[titles objectAtIndex:index]];
[item setImage:[UIImage imageNamed:[image_titles objectAtIndex:index]]];
[item setFinishedSelectedImage:[UIImage imageNamed:[[image_titles objectAtIndex:index] stringByAppendingString:#"_selected"]] withFinishedUnselectedImage:[UIImage imageNamed:[image_titles objectAtIndex:index]]];
[navigationController setTabBarItem:item];
[item release];
I ended up subclassing UITabBarController using three UIImageViews as each tab's selectionIndicatorBackground, and then using a further UIImageView to display the tab's glyph, and a UILabel for displaying its title.
Here is the code:
#interface LPTabBarController : UITabBarController
#property (nonatomic, retain) UIImageView *firstTab, *secondTab, *thirdTab, *firstTabBG, *secondTabBG, *thirdTabBG;
#property (nonatomic, retain) UILabel *firstTabLabel, *secondTabLabel, *thirdTabLabel;
#end
#implementation LPTabBarController
#synthesize firstTab, secondTab, thirdTab, firstTabBG, secondTabBG, thirdTabBG, firstTabLabel, secondTabLabel, thirdTabLabel;
- (id) init {
if ((self = [super init])) {
[self initialise];
}
return self;
}
- (void) setViewControllers:(NSArray *)viewControllers {
[self setViewControllers:viewControllers animated:NO];
}
- (void) setViewControllers:(NSArray *)viewControllers animated:(BOOL)animated {
[super setViewControllers:viewControllers animated:animated];
for (UITabBarItem *item in self.tabBar.items) {
[item setEnabled:NO];
}
}
- (void) initialise {
UIImageView *bg = [[UIImageView alloc] initWithFrame:CGRectMake(0, self.tabBar.frame.origin.y - 10, 320, 59)];
[bg setUserInteractionEnabled:YES];
[bg setImage:[UIImage imageNamed:#"tab_bar"]];
CGFloat widthbg = ceilf(self.view.frame.size.width / 3);
CGFloat heightbg = self.tabBar.frame.size.height;
CGFloat width = 23, y = 5;
UITapGestureRecognizer *gest = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(tapped:)];
self.firstTab = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:#"tab_bar_user"]] autorelease];
[self.firstTab setFrame:CGRectMake(ceilf((widthbg - width) / 2), y, 23, 23)];
self.firstTabLabel = [[[UILabel alloc] initWithFrame:CGRectMake(0, 27, widthbg, 20)] autorelease];
[self.firstTabLabel setTextAlignment:NSTextAlignmentCenter];
[self.firstTabLabel setText:#"Profile"];
[self.firstTabLabel setFont:[UIFont boldSystemFontOfSize:13]];
[self.firstTabLabel setTextColor:RGB(80, 23, 17)];
[self.firstTabLabel setShadowColor:[UIColor colorWithWhite:1 alpha:0.35]];
[self.firstTabLabel setShadowOffset:CGSizeMake(0, 1)];
[self.firstTabLabel setBackgroundColor:[UIColor clearColor]];
self.firstTabBG = [[[UIImageView alloc] initWithImage:nil] autorelease];
[self.firstTabBG setTag:01];
[self.firstTabBG setFrame:CGRectMake(0, 10, widthbg, heightbg)];
[self.firstTabBG addSubview:self.firstTab];
[self.firstTabBG addSubview:self.firstTabLabel];
[self.firstTabBG setUserInteractionEnabled:YES];
[self.firstTabBG addGestureRecognizer:gest];
[bg addSubview:self.firstTabBG];
[gest release];
gest = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(tapped:)];
self.secondTab = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:#"tab_bar_explore_selected"]] autorelease];
[self.secondTab setFrame:CGRectMake(ceilf((widthbg - width) / 2), y, 23, 23)];
self.secondTabLabel = [[[UILabel alloc] initWithFrame:CGRectMake(0, 27, widthbg, 20)] autorelease];
[self.secondTabLabel setTextAlignment:NSTextAlignmentCenter];
[self.secondTabLabel setText:#"Explore"];
[self.secondTabLabel setFont:[UIFont boldSystemFontOfSize:13]];
[self.secondTabLabel setTextColor:RGB(80, 23, 17)];
[self.secondTabLabel setShadowColor:[UIColor colorWithWhite:1 alpha:0.35]];
[self.secondTabLabel setShadowOffset:CGSizeMake(0, 1)];
[self.secondTabLabel setBackgroundColor:[UIColor clearColor]];
self.secondTabBG = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:#"tab_bar_selected_bg"]] autorelease];
[self.secondTabBG setTag:02];
[self.secondTabBG setUserInteractionEnabled:YES];
[self.secondTabBG addGestureRecognizer:gest];
[self.secondTabBG setFrame:CGRectMake(widthbg, 10, widthbg, heightbg)];
[self.secondTabBG addSubview:self.secondTab];
[self.secondTabBG addSubview:self.secondTabLabel];
[bg addSubview:self.secondTabBG];
[self tapped:gest];
[gest release];
gest = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(tapped:)];
self.thirdTab = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:#"tab_bar_settings"]] autorelease];
[self.thirdTab setFrame:CGRectMake(ceilf((widthbg - width) / 2), y, 23, 23)];
self.thirdTabLabel = [[[UILabel alloc] initWithFrame:CGRectMake(0, 27, widthbg, 20)] autorelease];
[self.thirdTabLabel setTextAlignment:NSTextAlignmentCenter];
[self.thirdTabLabel setText:#"Settings"];
[self.thirdTabLabel setFont:[UIFont boldSystemFontOfSize:13]];
[self.thirdTabLabel setTextColor:RGB(80, 23, 17)];
[self.thirdTabLabel setShadowColor:[UIColor colorWithWhite:1 alpha:0.35]];
[self.thirdTabLabel setShadowOffset:CGSizeMake(0, 1)];
[self.thirdTabLabel setBackgroundColor:[UIColor clearColor]];
self.thirdTabBG = [[[UIImageView alloc] initWithImage:nil] autorelease];
[self.thirdTabBG setTag:03];
[self.thirdTabBG setFrame:CGRectMake(widthbg * 2, 10, widthbg, heightbg)];
[self.thirdTabBG addSubview:self.thirdTab];
[self.thirdTabBG addSubview:self.thirdTabLabel];
[self.thirdTabBG setUserInteractionEnabled:YES];
[self.thirdTabBG addGestureRecognizer:gest];
[bg addSubview:self.thirdTabBG];
[gest release];
[self.view addSubview:bg];
[bg release];
}
static int lastIndex = 2;
- (void) tapped:(UITapGestureRecognizer *) gest {
switch (lastIndex) {
case 1:
[self.firstTab setImage:[UIImage imageNamed:#"tab_bar_user"]];
[self.firstTabBG setImage:nil];
[self.firstTabLabel setTextColor:RGB(80, 23, 17)];
[self.firstTabLabel setShadowColor:[UIColor colorWithWhite:1 alpha:0.35]];
[self.firstTabLabel setShadowOffset:CGSizeMake(0, 1)];
break;
case 2:
[self.secondTab setImage:[UIImage imageNamed:#"tab_bar_explore"]];
[self.secondTabBG setImage:nil];
[self.secondTabLabel setTextColor:RGB(80, 23, 17)];
[self.secondTabLabel setShadowColor:[UIColor colorWithWhite:1 alpha:0.35]];
[self.secondTabLabel setShadowOffset:CGSizeMake(0, 1)];
break;
case 3:
[self.thirdTab setImage:[UIImage imageNamed:#"tab_bar_settings"]];
[self.thirdTabBG setImage:nil];
[self.thirdTabLabel setTextColor:RGB(80, 23, 17)];
[self.thirdTabLabel setShadowColor:[UIColor colorWithWhite:1 alpha:0.35]];
[self.thirdTabLabel setShadowOffset:CGSizeMake(0, 1)];
break;
}
switch (gest.view.tag) {
case 1 :{
[self setSelectedIndex:0];
[self.firstTab setImage:[UIImage imageNamed:#"tab_bar_user_selected"]];
[self.firstTabBG setImage:[UIImage imageNamed:#"tab_bar_selected_bg"]];
[self.firstTabLabel setTextColor:RGB(252, 208, 170)];
[self.firstTabLabel setShadowColor:RGB(80, 23, 17)];
[self.firstTabLabel setShadowOffset:CGSizeMake(0, -1)];
break;
}
case 2: {
[self setSelectedIndex:1];
[self.secondTab setImage:[UIImage imageNamed:#"tab_bar_explore_selected"]];
[self.secondTabBG setImage:[UIImage imageNamed:#"tab_bar_selected_bg"]];
[self.secondTabLabel setTextColor:RGB(252, 208, 170)];
[self.secondTabLabel setShadowColor:RGB(80, 23, 17)];
[self.secondTabLabel setShadowOffset:CGSizeMake(0, -1)];
break;
}
case 3: {
[self setSelectedIndex:2];
[self.thirdTab setImage:[UIImage imageNamed:#"tab_bar_settings_selected"]];
[self.thirdTabBG setImage:[UIImage imageNamed:#"tab_bar_selected_bg"]];
[self.thirdTabLabel setTextColor:RGB(252, 208, 170)];
[self.thirdTabLabel setShadowColor:RGB(80, 23, 17)];
[self.thirdTabLabel setShadowOffset:CGSizeMake(0, -1)];
break;
}
}
lastIndex = gest.view.tag;
}
- (void) dealloc {
[firstTab release];
[firstTabBG release];
[secondTab release];
[secondTabBG release];
[thirdTab release];
[thirdTabBG release];
[firstTabLabel release];
[secondTabLabel release];
[thirdTabLabel release];
[super dealloc];
}

UIView Animation Block Not Doing Anything

I have a very small animation I want to do by moving a view's frame using blocks (rather than the animation headers).
My view hierarchy is quite big so I will explain everything in regards of the specific view I want to animate.
The biggest view is the one that takes the whole screen, so it is 320x480 points. Inside this view, I have another view called "keypadContainerView" that is 320x200 points, located on 0, 261 and it appears at the bottom of the screen. This keypadContainerView has a subview called keypadView, which has a bunch of small buttons as subviews.
Biggest View -> KeypadContainerView -> keypadView -> UIbuttons.
An screenshot:
Although this could go without saying, the keypad there is the keypadContainerView, with is't keypadView and buttons. I need this hierarchy because I'm aiming for eye candy here, and each layer has a different background.
The way I create and deal with that view is here:
keypadViewContainer = [[[UIView alloc] initWithFrame:CGRectMake(0, 261, 320, 200)] autorelease]; //(Original is 0, 261, 320, 200)
keypadView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 200)];
[keypadViewContainer addSubview:keypadView];
//Add the buttons
[self.view addSubview:keypadViewContainer];
And this is how I'm trying to animate it:
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[UIView animateWithDuration:5.0 animations:^{
self.keypadViewContainer.frame = CGRectMake(0, 0, 320, 200);
} completion:NULL];
}
What is funny is that if I NSLog something in the animations: parameter, I actually get some output so the method is definitely getting called. It's just not animating anything at all.
The whole controller code is here, in case you need it:
//UnlockKeyboardViewController
//------------------------------------------------------------------------
#interface UnlockKeyboardViewController : UIViewController
{
NSArray *buttons;
NSArray *passcodeFields;
UIImage *buttonBackgroundImage;
UIImage *buttonBackgroundHighlightedImage;
UIImage *middleButtonBackgroundImage;
UIImage *middleButtonBackgroundImageHighlighted;
UIImage *screenBackgroundImage;
UIImage *infoViewContainerImage;
UIImage *keypadViewContainerImage;
UIImage *passcodeFieldsContainerImage;
UIImage *infoViewImage;
UIImage *passcodeViewImage;
UIView *infoViewContainer;
UIView *keypadViewContainer;
UIView *passcodeFieldsContainer;
UIView *infoView;
UIView *keypadView;
UIView *passcodeFieldsView;
UIView *infoToDisplayView; //The view the programmer passes to show in infoView.
}
#property(nonatomic, retain)UIImage *buttonBackgroundImage;
#property(nonatomic, retain)UIImage *buttonBackgroundHighlightedImage;
#property(nonatomic, retain)UIImage *screenBackgroundImage;
#property(nonatomic, retain)UIImage *keypadViewBackgroundImage;
#property(nonatomic, retain)UIImage *infoViewContainerImage;
#property(nonatomic, retain)UIImage *keypadViewContainerImage;
#property(nonatomic, retain)UIImage *passcodeFieldsContainerImage;
#property(nonatomic, retain)UIImage *infoViewImage;
#property(nonatomic, retain)UIImage *passcodeViewImage;
#property(nonatomic, retain)UIView *infoToDisplayView;
//Properties for container views.
#property(nonatomic, retain)UIView *infoViewContainer;
#property(nonatomic, retain)UIView *keypadViewContainer;
#property(nonatomic, retain)UIView *passcodeFieldsContainer;
#end
#implementation UnlockKeyboardViewController
#synthesize buttonBackgroundImage = _buttonBackgroundImage;
#synthesize buttonBackgroundHighlightedImage = _buttonBackgroundHighlightedImage;
#synthesize screenBackgroundImage = _screenBackgroundImage;
#synthesize keypadViewBackgroundImage = _keypadViewBackgroundImage;
#synthesize infoViewContainerImage = _infoViewContainerImage;
#synthesize keypadViewContainerImage = _keypadViewContainerImage;
#synthesize passcodeFieldsContainerImage = _passcodeFieldsContainerImage;
#synthesize infoViewImage = _infoViewImage;
#synthesize passcodeViewImage = _passcodeViewImage;
#synthesize infoToDisplayView = _infoToDisplayView;
//Synthesizers for container views.
#synthesize infoViewContainer = _infoViewContainer;
#synthesize keypadViewContainer = _keypadViewContainer;
#synthesize passcodeFieldsContainer = _passcodeFieldsContainer;
-(void)loadView
{
[super loadView];
self.view.frame = CGRectMake(0, 0, 320, 480);
_unlockKeyboardBundle = [NSBundle bundleForClass:[self class]];
buttonBackgroundImage = [UIImage imageWithContentsOfFile:[_unlockKeyboardBundle pathForResource:#"button" ofType:#"png"]];
middleButtonBackgroundImage = [UIImage imageWithContentsOfFile:[_unlockKeyboardBundle pathForResource:#"middleButton" ofType:#"png"]];
buttonBackgroundHighlightedImage = [UIImage imageWithContentsOfFile:[_unlockKeyboardBundle pathForResource:#"pushedButton" ofType:#"png"]];
middleButtonBackgroundImageHighlighted = [UIImage imageWithContentsOfFile:[_unlockKeyboardBundle pathForResource:#"pushedButtonMiddle" ofType:#"png"]];
infoViewContainerImage = [UIImage imageWithContentsOfFile:[_unlockKeyboardBundle pathForResource:#"infoViewContainerImage" ofType:#"png"]];
keypadViewContainerImage = [UIImage imageWithContentsOfFile:[_unlockKeyboardBundle pathForResource:#"keypadViewContainerImage" ofType:#"png"]];
passcodeFieldsContainerImage = [UIImage imageWithContentsOfFile:[_unlockKeyboardBundle pathForResource:#"passcodeViewContainerImage" ofType:#"png"]];
infoViewImage = [UIImage imageWithContentsOfFile:[_unlockKeyboardBundle pathForResource:#"infobackground" ofType:#"png"]];
passcodeViewImage = [UIImage imageWithContentsOfFile:[_unlockKeyboardBundle pathForResource:#"passcodescreen" ofType:#"png"]];
//self.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageWithContentsOfFile:[_unlockKeyboardBundle pathForResource:#"lockbackground" ofType:#"png"]]];
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
keypadViewContainer = [[[UIView alloc] initWithFrame:CGRectMake(0, 261, 320, 200)] autorelease]; //(Original is 0, 261, 320, 200)
keypadView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 200)];
[keypadViewContainer addSubview:keypadView];
keypadViewContainer.backgroundColor = [UIColor colorWithPatternImage:keypadViewContainerImage];
NSMutableArray *tempButtons = [NSMutableArray array];
self.view.opaque = YES;
UIButton *button1 = [UIButton buttonWithType:UIButtonTypeCustom];
[button1 setTitle:#"1" forState:UIControlStateNormal];
button1.frame = CGRectMake(0, 0, 106, 50);
UIButton *button4 = [UIButton buttonWithType:UIButtonTypeCustom];
[button4 setTitle:#"4" forState:UIControlStateNormal];
button4.frame = CGRectMake(0, 50, 106, 50);
UIButton *button7 = [UIButton buttonWithType:UIButtonTypeCustom];
[button7 setTitle:#"7" forState:UIControlStateNormal];
button7.frame = CGRectMake(0, 100, 106, 50);
UIButton *cancel = [UIButton buttonWithType:UIButtonTypeCustom];
[cancel setTitle:NSLocalizedString(#"cancel", #"Cancel string") forState:UIControlStateNormal];
cancel.frame = CGRectMake(0, 150, 106, 50);
UIButton *button2 = [UIButton buttonWithType:UIButtonTypeCustom];
[button2 setTitle:#"2" forState:UIControlStateNormal];
button2.frame = CGRectMake(106, 0, 108, 50);
UIButton *button5 = [UIButton buttonWithType:UIButtonTypeCustom];
[button5 setTitle:#"5" forState:UIControlStateNormal];
button5.frame = CGRectMake(106, 50, 108, 50);
UIButton *button8 = [UIButton buttonWithType:UIButtonTypeCustom];
[button8 setTitle:#"8" forState:UIControlStateNormal];
button8.frame = CGRectMake(106, 100, 108, 50);
UIButton *button0 = [UIButton buttonWithType:UIButtonTypeCustom];
[button0 setTitle:#"0" forState:UIControlStateNormal];
button0.frame = CGRectMake(106, 150, 108, 50);
UIButton *button3 = [UIButton buttonWithType:UIButtonTypeCustom];
[button3 setTitle:#"3" forState:UIControlStateNormal];
button3.frame = CGRectMake(214, 0, 106, 50);
UIButton *button6 = [UIButton buttonWithType:UIButtonTypeCustom];
[button6 setTitle:#"6" forState:UIControlStateNormal];
button6.frame = CGRectMake(214, 50, 106, 50);
UIButton *button9 = [UIButton buttonWithType:UIButtonTypeCustom];
[button9 setTitle:#"9" forState:UIControlStateNormal];
button9.frame = CGRectMake(214, 100, 106, 50);
UIButton *cancelOrDelete = [UIButton buttonWithType:UIButtonTypeCustom];
[cancelOrDelete setTitle:#"<-" forState:UIControlStateNormal];
cancelOrDelete.frame = CGRectMake(214, 150, 108, 50);
[tempButtons addObject:button1];
[tempButtons addObject:button2];
[tempButtons addObject:button3];
[tempButtons addObject:button4];
[tempButtons addObject:button5];
[tempButtons addObject:button6];
[tempButtons addObject:button7];
[tempButtons addObject:button8];
[tempButtons addObject:button9];
[tempButtons addObject:button0];
[tempButtons addObject:cancel];
[tempButtons addObject:cancelOrDelete];
buttons = [[NSArray arrayWithArray:tempButtons] retain];
for(UIButton *theButton in buttons)
{
if([theButton.currentTitle isEqualToString:#"2"] || [theButton.currentTitle isEqualToString:#"5"] || [theButton.currentTitle isEqualToString:#"8"] || [theButton.currentTitle isEqualToString:#"0"])
{
[theButton setBackgroundImage:middleButtonBackgroundImage forState:UIControlStateNormal];
[theButton setBackgroundImage:middleButtonBackgroundImageHighlighted forState:UIControlStateHighlighted];
}else
{
[theButton setBackgroundImage:buttonBackgroundImage forState:UIControlStateNormal];
[theButton setBackgroundImage:middleButtonBackgroundImageHighlighted forState:UIControlStateHighlighted];
}
[keypadView addSubview:theButton];
}
[self.view addSubview:keypadViewContainer];
passcodeFieldsView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0,320, 110)] autorelease];
passcodeFieldsContainer = [[[UIView alloc] initWithFrame:CGRectMake(0, 151, 320, 110)] autorelease];
passcodeFieldsContainer.backgroundColor = [UIColor colorWithPatternImage:passcodeFieldsContainerImage];
passcodeFieldsView.backgroundColor = [UIColor colorWithPatternImage:passcodeViewImage];
NSMutableArray *passTemps = [NSMutableArray array];
UITextField *tf1 = [[[UITextField alloc] initWithFrame:CGRectMake(24, 27, 50, 50)] autorelease];
UITextField *tf2 = [[[UITextField alloc] initWithFrame:CGRectMake(98, 27, 50, 50)] autorelease];
UITextField *tf3 = [[[UITextField alloc] initWithFrame:CGRectMake(172, 27, 50, 50)] autorelease];
UITextField *tf4 = [[[UITextField alloc] initWithFrame:CGRectMake(246, 27, 50, 50)] autorelease];
[passTemps addObject:tf1];
[passTemps addObject:tf2];
[passTemps addObject:tf3];
[passTemps addObject:tf4];
passcodeFields = [[NSArray arrayWithArray:passTemps] retain];
for(UITextField *theTf in passcodeFields)
{
theTf.borderStyle = UITextBorderStyleBezel;
theTf.backgroundColor = [UIColor whiteColor];
theTf.enabled = NO;
theTf.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
theTf.textAlignment = UITextAlignmentCenter;
theTf.adjustsFontSizeToFitWidth = YES;
theTf.alpha = 0.7;
theTf.secureTextEntry = YES;
[passcodeFieldsView addSubview:theTf];
}
[passcodeFieldsContainer addSubview:passcodeFieldsView];
[self.view addSubview:passcodeFieldsContainer];
infoView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 151)] autorelease];
infoView.backgroundColor = [UIColor colorWithPatternImage:infoViewImage];
infoViewContainer = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 151)] autorelease];
infoViewContainer.backgroundColor = [UIColor colorWithPatternImage:infoViewContainerImage];
[infoViewContainer addSubview:infoView];
[self.view addSubview:infoViewContainer];
[pool drain];
}
-(void)viewDidLoad
{
[super viewDidLoad];
}
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[UIView animateWithDuration:5.0 animations:^{
self.keypadViewContainer.frame = CGRectMake(0, 0, 320, 200);
} completion:NULL];
}
-(void)dealloc
{
[buttons release];
[passcodeFields release];
[buttonBackgroundImage release];
[buttonBackgroundHighlightedImage release];
[screenBackgroundImage release];
[infoView release];
[keypadView release];
[passcodeFieldsView release];
[infoViewContainerImage release];
[keypadViewContainerImage release];
[passcodeFieldsContainerImage release];
[infoViewImage release];
[passcodeViewImage release];
[infoToDisplayView release];
[super dealloc];
}
#end
I have a small feeling it may have something to do with the way I'm dealing with my views, so there's the whole source code.
Any help with this will be highly appreciated.
Instead of those :
keypadViewContainer = [[[UIView alloc] initWithFrame:CGRectMake(0, 261, 320, 200)] autorelease];
Use
Self.keypadViewContainer = .....
and your #synthesize are wrong.
You declare iVars explicitly without underscore,
But use synthesize to create underscored iVars.
So your properties correspond to
_keypadViewContainer
but in your loadView you assign to keypadViewController
Quickest fix: just use #synthesize instead of synthesize = ...
(that is only if you don't use Xcode 4.4!)
Best fix: get rid of the explicit iVar declaration and
Make sure to use _keypadViewContainer etc. when you access iVar directly like in dealloc.
Ideal fix: use ARC and use IB to build your keypad interface (why don't you btw?)

ActionSheet in NavController with TabBarController - Exc_Bad_Access

I'm currently have a weird problem.
I have an actionsheet with pickerView in with two button (cancel, and Ok).
They work perfectly until i choose a value in that picker and i click on the first button of my TabBarController which contain my NavigationController.
My actionsheet is declared in my .h and has property (nonatomic, retain), i release it in my dealloc function.
I have an exc_bad_access if i release this object and i dont know why because i allocated it.
This is my function which create my Actionsheet if is nil, and build it.
- (IBAction)select_marque :(id)sender
{
if (!actionSheet_marque)
{
actionSheet_marque = [[UIActionSheet alloc] initWithTitle:nil delegate:nil cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
}
[actionSheet_marque setActionSheetStyle:UIActionSheetStyleBlackTranslucent];
CGRect pickerFrame = CGRectMake(0, 40, 0, 0);
picker_marque = [[UIPickerView alloc] initWithFrame: pickerFrame];
picker_marque.showsSelectionIndicator = YES;
picker_marque.dataSource = self;
picker_marque.delegate = self;
[actionSheet_marque addSubview: picker_marque];
[picker_marque release];
UILabel *lbl = [[UILabel alloc] initWithFrame: CGRectMake(110, 7.0f, 150.0f, 30.0f)];
lbl.text = #"Marque";
lbl.backgroundColor = [UIColor clearColor];
lbl.textColor = [UIColor whiteColor];
[actionSheet_marque addSubview:lbl];
[lbl release];
UISegmentedControl *closeButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:#"Ok"]];
closeButton.momentary = YES;
closeButton.frame = CGRectMake(260, 7.0f, 50.0f, 30.0f);
closeButton.segmentedControlStyle = UISegmentedControlStyleBar;
closeButton.tintColor = [UIColor blueColor];
[closeButton addTarget:self action:#selector(dismissActionSheet:) forControlEvents:UIControlEventValueChanged];
[actionSheet_marque addSubview:closeButton];
[closeButton release];
UISegmentedControl *cancelButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:#"Cancel"]];
cancelButton.momentary = YES;
cancelButton.frame = CGRectMake(5, 7.0f, 50.0f, 30.0f);
cancelButton.segmentedControlStyle = UISegmentedControlStyleBar;
cancelButton.tintColor = [UIColor redColor];
cancelButton.tag = 1;
[cancelButton addTarget:self action:#selector(cancelActionSheet:) forControlEvents:UIControlEventValueChanged];
[actionSheet_marque addSubview:cancelButton];
[cancelButton release];
[actionSheet_marque showInView: self.navigationController.view];
[actionSheet_marque setBounds:CGRectMake(0, 0, 320, 485)];
}
I check also if the pointer is nil in dealloc method....
Thanks
If you have property of UIActionsheet then you should use self.actionSheet_marque when you allocate it. Try changing code like this
if (!actionSheet_marque)
{
self.actionSheet_marque = [[[UIActionSheet alloc] initWithTitle:nil delegate:nil cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil] autorelease];
}
[self.actionSheet_marque setActionSheetStyle:UIActionSheetStyleBlackTranslucent];
And in whole function except this line if (!actionSheet_marque)