我将一个UISearchBar拖到我的xib上,将它连接到我的文件所有者的委托和searchBar作为插座。当我用搜索栏切换到视图时,我遇到了崩溃。我不知道我做错了什么,我是否需要在停止崩溃之前实现搜索栏委托方法?
#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
答案 0 :(得分:0)
它实际上是一个问题,它是如何连接到xib文件中的,与.h / .m文件无关。
答案 1 :(得分:-1)
这是dealloc的问题。你已经发布了searchBar。你没有分配它。所以不要发布它。
答案 2 :(得分:-1)
为什么你发布了你的searchBar,你从来没有为它分配任何内存,因此你无法释放它。