簡體   English   中英

搜索欄ResignFirstResponder隱藏項目

[英]Search Bar ResignFirstResponder hides Items

我的應用中有這個搜索欄 請參閱播放,下一個和上一個按鈕。

當我搜索並點擊搜索項目中的一首歌時,搜索欄的第一響應者會隱藏我的按鈕,即播放,下一個和上一個按鈕。

我正在使用此代碼

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{

MPMediaItem * song;
_nowPlayingIndex=indexPath.row;

if (tableView == self.searchDisplayController.searchResultsTableView)
    song = searchResults[_nowPlayingIndex];
else
    song = _songs[_nowPlayingIndex];

[self.musicPlayer setNowPlayingItem:song];
[self.musicPlayer play];
_playButton.hidden=true;
_pauseButton.hidden=false;

[_mySearchBar resignFirstResponder];

}

為什么隱藏我的按鈕?

第1步:您可以做的是顯示和隱藏這些按鈕或任何其他項目的不同功能。

第2步:然后您可以在需要的地方調用這些功能。 例如,每當你辭職的應答者之后。

第3步:您可以嘗試將表格視圖框架設置為距代碼更低的高度。 然后測試這個東西。 因為我認為桌面視圖的高度會導致隱藏這些按鈕。
例如[self.tableView setFrame: CGRectMake(self.view.frame.origin.x, self.searchSong.frame.origin.y, self.view.frame.size.width, self.view.frame.size.height - "button.height" - "navbar.height")];

第4步:您還應該調試代碼,以便執行resignFirstResponder ...請檢查按鈕的框架是什么。 這樣你就可以了解他們的位置。

它只是解決問題的另一種方式。 如果您仍有疑問,可以提問。 我希望它有效。 :)

這就是我想要的

- (void)searchDisplayController:(UISearchDisplayController *)controller didShowSearchResultsTableView:(UITableView *)tableView{
CGRect tableFrame= self.searchDisplayController.searchResultsTableView.frame;
tableFrame.size.height=200;
tableFrame.size.width=300;
[self.searchDisplayController.searchResultsTableView setFrame:tableFrame];
[self.searchDisplayController.searchResultsTableView reloadData];

}

而這[[myButton superview]帶來了SubviewToFront:myButton]; 把它們帶到前面。

當您搜索任何內容時,應用代碼到您的按鈕是搜索代理

 [grayBar bringSubViewToFront];

要么

 [yourButton1 bringSubViewToFront];
 [yourButton2 bringSubViewToFront];
 [yourButton3 bringSubViewToFront];

希望這可以幫助

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM