2013-06-26 164 views
-3

在我的應用程序中,我有選項卡欄,並在其中有三個選項卡按鈕。但在其中的一個,當我第二次按它它崩潰的應用程序。其他按鈕工作正常。第二次點擊標籤按鈕時應用程序崩潰

這是.m文件代碼

-(void)viewWillAppear:(BOOL)animated 
{ 
    scrollView.contentSize = CGSizeMake(320, 500); 
    [super viewWillAppear:YES]; 
} 

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) { 
     self.title = NSLocalizedString(@"Contact Us", @"Contact Us"); 
     self.tabBarItem.image = [UIImage imageNamed:@"contactTab.png"]; 
    } 
    return self; 
} 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view from its nib. 

    [self.navigationController.navigationBar setTintColor:[UIColor blackColor]]; 

    scrollView.contentSize = CGSizeMake(320, 500); 
    scrollView.scrollEnabled = YES; 

    [[NSNotificationCenter defaultCenter] addObserver:self 
              selector:@selector(keyboardWasShown:) 
               name:UIKeyboardDidShowNotification 
               object:nil]; 

    [[NSNotificationCenter defaultCenter] addObserver:self 
              selector:@selector(keyboardWillHide:) 
               name:UIKeyboardWillHideNotification 
               object:nil]; 
} 

- (void)didReceiveMemoryWarning 
{ 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    [self.view endEditing:YES]; 
} 

-(BOOL) textFieldShouldReturn:(UITextField *)textField 
{ 
    [textField resignFirstResponder]; 
    return YES; 
} 

- (BOOL)textViewShouldBeginEditing:(UITextView *)textView 
{ 
    [textView becomeFirstResponder]; 
    return YES; 
} 

- (void)keyboardWasShown:(NSNotification *)notification 
{ 

    // Step 1: Get the size of the keyboard. 
    CGSize keyboardSize = [[[notification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size; 


    // Step 2: Adjust the bottom content inset of your scroll view by the keyboard height. 
    UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0, 0.0, keyboardSize.height, 0.0); 
    scrollView.contentInset = contentInsets; 
    scrollView.scrollIndicatorInsets = contentInsets; 


    // Step 3: Scroll the target text field into view. 
    CGRect aRect = self.view.frame; 
    aRect.size.height -= keyboardSize.height; 
    if (!CGRectContainsPoint(aRect, self.activeTextField.frame.origin)) 
    { 
     CGPoint scrollPoint = CGPointMake(0.0, self.activeTextField.frame.origin.y - (keyboardSize.height-15)); 
     [scrollView setContentOffset:scrollPoint animated:YES]; 
    } 
} 

- (void) keyboardWillHide:(NSNotification *)notification 
{ 
    UIEdgeInsets contentInsets = UIEdgeInsetsZero; 
    scrollView.contentInset = contentInsets; 
    scrollView.scrollIndicatorInsets = contentInsets; 
} 

// Set activeTextField to the current active textfield 
- (void)textFieldDidBeginEditing:(UITextField *)textField 
{ 
    self.activeTextField = textField; 
} 

// Set activeTextField to nil 
- (void)textFieldDidEndEditing:(UITextField *)textField 
{ 
    self.activeTextField = nil; 
} 

// Dismiss the keyboard 
- (IBAction)dismissKeyboard:(id)sender 
{ 
    [self.activeTextField resignFirstResponder]; 
} 

所以其代碼崩潰我的應用程序?

編輯:

AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 

tabBarController = [[UITabBarController alloc] init]; 

//Adding Search,Nearby,Map,AboutUs,Favorites Tabs to tabBarController 
HomeViewController * homeViewController = [[HomeViewController alloc] init]; 
UINavigationController *homeNav = [[UINavigationController alloc] initWithRootViewController:homeViewController]; 

ContactUsFormViewController *contactUsFormViewController = [[ContactUsFormViewController alloc] init]; 
UINavigationController *contactNav = [[UINavigationController alloc] initWithRootViewController:contactUsFormViewController]; 

BookingFormViewController *bookingFormViewController = [[BookingFormViewController alloc] init]; 
UINavigationController *bookingNav = [[UINavigationController alloc] initWithRootViewController:bookingFormViewController]; 

NSArray* controllers = [NSArray arrayWithObjects:homeNav,contactNav,bookingNav, nil]; 

tabBarController.viewControllers = controllers; 

[self.window setRootViewController:tabBarController]; 

sleep(2); 

[self.window makeKeyAndVisible]; 
return YES; 

} 

log of crash

感謝。

+3

這是否是崩潰日誌? – adali

+0

可以告訴我們錯誤名稱或錯誤日誌? –

+0

你使用自定義tabbarcontroller嗎? – Jasper

回答

1
- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view from its nib. 


} 


-(void)viewWillAppear:(BOOL)animated 
{ 
    [self.navigationController.navigationBar setTintColor:[UIColor blackColor]]; 

    scrollView.contentSize = CGSizeMake(320, 500); 
    scrollView.scrollEnabled = YES; 

    [[NSNotificationCenter defaultCenter] addObserver:self 
              selector:@selector(keyboardWasShown:) 
               name:UIKeyboardDidShowNotification 
               object:nil]; 

    [[NSNotificationCenter defaultCenter] addObserver:self 
              selector:@selector(keyboardWillHide:) 
               name:UIKeyboardWillHideNotification 
               object:nil]; 

    scrollView.contentSize = CGSizeMake(320, 500); 
    [super viewWillAppear:YES]; 
} 

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) { 
     self.title = NSLocalizedString(@"Contact Us", @"Contact Us"); 
     self.tabBarItem.image = [UIImage imageNamed:@"contactTab.png"]; 
    } 
    return self; 
} 
+0

非常感謝您的回答。它解決了我的問題。我接受這個答案。 – Zeel

+0

welcome frnd .. ,,,,, –

相關問題