2011-07-13 11 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を解放しました。割り当てられていません。解放しないでください。

+0

ええと、私はあなたがそれをやるべきだとはかなり確信しています。保持されているプロパティとして設定されています。しかし、とにかく、私はそれを削除した後でも、私はまだ同じ問題があります。 – Vadoff

-1

なぜあなたはあなたのsearchBarを解放したのですか?それを解放することができないように、あなたは決してメモリを割り当てませんでした。

関連する問題