2011-07-13 43 views
0

我將UISearchBar拖到我的xib上,將它掛接到我的文件的所有者,委託和searchBar作爲插座。使用搜索欄切換到視圖時出現崩潰。我不知道我在做什麼錯,我是否需要在停止崩潰之前實施搜索欄委託方法?當試圖實現UISearchBar時,程序崩潰時出現NSException

#import <UIKit/UIKit.h> 

@interface ThirdViewController : UIViewController { 
@private UISearchBar *searchBar_; 
} 
@property (nonatomic, retain) IBOutlet UISearchBar *searchBar; 

@end 

#import "ThirdViewController.h" 

@implementation ThirdViewController 
@synthesize 
    searchBar = searchBar_; 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
} 

- (void)didReceiveMemoryWarning { 
    // Releases the view if it doesn't have a superview. 
    [super didReceiveMemoryWarning]; 

    // Release any cached data, images, etc. that aren't in use. 
} 

- (void)viewDidUnload { 
    [super viewDidUnload]; 

    // Release any retained subviews of the main view. 
    // e.g. self.myOutlet = nil; 
} 

- (void)dealloc { 
    [searchBar_ release], searchBar_ = nil; 
    [super dealloc]; 
} 

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 
    [self.searchBar resignFirstResponder]; 
} 

@end 
+1

你可以添加崩潰日誌嗎? 'dealloc'方法沒有錯。 –

回答

0

這實際上是一個問題,它是如何掛在xib文件中的,與.h/.m文件無關。

-1

這是dealloc的問題。你發佈了searchBar.You沒有分配它,所以不要釋放它。

+0

嗯,我很確定這就是你應該這樣做的。因爲它被設置爲保留屬性。但無論如何,即使我已經刪除它,我仍然有同樣的問題。 – Vadoff

-1

爲什麼你釋放你的searchBar,你從來沒有分配任何內存,所以你不能釋放它。

相關問題