Ios UISearchBar在模拟器上工作,但在设备上不工作

Ios UISearchBar在模拟器上工作,但在设备上不工作,ios,uikit,ios-simulator,device,uisearchbar,Ios,Uikit,Ios Simulator,Device,Uisearchbar,我正在我的应用程序中使用UISearchBar。当我在模拟器上运行时,一切都很好。在设备上无法工作。在设备上,我的搜索栏框架正在更改,但keybord未显示。网络日志正在运行。我的代码在这里: -(void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText { NSLog(@"wrote"); } -(BOOL)searchBarShouldBeginEditing:(UISearchBar

我正在我的应用程序中使用UISearchBar。当我在模拟器上运行时,一切都很好。在设备上无法工作。在设备上,我的搜索栏框架正在更改,但keybord未显示。网络日志正在运行。我的代码在这里:

-(void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {

    NSLog(@"wrote");
}

-(BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar {

    [self.mySearchBar setFrame:CGRectMake(0,100,mySearchBar.frame.size.width,mySearchBar.frame.size.height)];
    mySearchBar.showsCancelButton=TRUE;
    mySearchBar.text=@"nowwrite";
    NSLog(@"chosed");    
}

-(void)searchBarCancelButtonClicked:(UISearchBar *)searchBar {

    NSLog(@"cancel");
}

- (void)viewDidLoad
{
    mySearchBar.delegate=self;
    [super viewDidLoad];
}
还有我的.h文件

@interface sehirRehberi : UIViewController <UISearchBarDelegate,MKMapViewDelegate,CLLocationManagerDelegate,UINavigationControllerDelegate> {
    IBOutlet UISearchBar *mySearchBar;
}

@property(retain, nonatomic) UISearchBar *mySearchBar;

你有没有看到第一反应者?这是键盘显示所必需的。我不知道为什么它会在模拟器上工作,但你应该打电话给[自我成为第一反应者];在viewDidLoad方法中,使视图能够接收键盘事件,从而显示键盘。当您完成查看将消失等操作后,只需致电[自我辞职第一响应者];。我想这是你的问题。如果没有更多的解释/代码,很难判断。

我遇到了类似的问题,即“UISearchBar”出现在模拟器中,而不是实际设备中。我通过在nib文件中放置UISearchBar时使用NibName调用构造函数修复了这个问题

[MyUITableViewController initWithNibName:@"MyUITableViewController" bundle:nil];

很难理解发生了什么事。尝试编辑您的问题并添加日志错误。谢谢。我没有错误日志。因为我没有错误。一切似乎都很好。但是uisearchbar不起作用。我的nslogs工作正常,但keybord没有看到,我在想一个错误。这很奇怪。P.S.类名通常以大写字母开头。我在clicked方法中调用becomefirstresponder:就像这样clickedShouldBeganTextEdit。错了吗?我必须在viewdidload中调用它吗?对不起,我现在不在电脑上是的,在viewdidload或viewdidload出现时调用它应该可以让它工作。真的吗?该死要更多地诊断问题,我需要更多的代码。你所写的一切看起来都很好。设备上的iOS版本是什么?