我写了一个Serach条形码,但是那个在iPhone设备上运行完美但在iPad上没有运行

时间:2016-08-17 13:36:24

标签: ios iphone swift ipad

iPad不会显示,我想要什么

单击搜索按钮时,导航栏的TitleView设置为搜索栏 并在搜索栏前面显示取消按钮。 但在iPad取消按钮不显示这是我的问题。

This is the Actual result on All iPhone Device

But when I Execute With iPad,then code shows like this,cancel button is not display front of search bar

我的代码在这里

class MenuTableViewController: UITableViewController,UISearchBarDelegate{
//MARK: - Declare Variable

let searchBar = UISearchBar()
var image = UIImage()
var menuList:NSMutableArray = ["About Us","Packages","Locations","Hot News","Testimonials","FAQ's","Contact"]
let colorArray:[UIColor] = [UIColor.blackColor(),UIColor.blueColor(),UIColor.brownColor(),UIColor.cyanColor(),UIColor.purpleColor(),UIColor.greenColor(),UIColor.orangeColor()]

//MARK: - Outlet variable

//MARK: - Outlet Methods

//MARK: - ViewDidLoad
override func viewDidLoad() {
    super.viewDidLoad()

    // Uncomment the following line to preserve selection between presentations
    // self.clearsSelectionOnViewWillAppear = false

    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem()

    self.navigationController?.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: UIBarMetrics.Default)
    self.navigationController?.navigationBar.shadowImage = UIImage()
    self.navigationController?.navigationBar.translucent = true


    image = UIImage(named: "photo.png")!
    self.navigationItem.titleView = UIImageView(image: image)
    self.navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: .Search, target: self, action:(#selector(MenuTableViewController.searchData)))
    self.navigationItem.rightBarButtonItem = UIBarButtonItem(image: UIImage(named: "399-list1"), style: .Done, target: self, action: (#selector(MenuTableViewController.menuDisplay)))

    self.searchBar.showsCancelButton = true
    self.searchBar.delegate = self

}

//MRAK: - SerachBar Delegate Methods

func searchBarCancelButtonClicked(searchBar: UISearchBar) {
    print("Cancel")
    self.navigationItem.titleView = UIImageView(image: image)
    self.navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: .Search, target: self, action:(#selector(MenuTableViewController.searchData)))
}

//MARK: - Search Methods
func searchData() {
    print("done search")
    self.navigationItem.leftBarButtonItem = nil;
    // add the search bar (which will start out hidden).
    self.navigationItem.titleView = searchBar;
    searchBar.becomeFirstResponder()
}

//MARK: - Menu Display Methods
func menuDisplay() {
    print("display menu")
}

0 个答案:

没有答案