2015-06-18 15 views
6

Tôi đang cố gắng tìm kiếm trong UITableViewController bằng UISearchController. Đối với dự án khởi động tôi sử dụng Apple's example. Tôi đã thực hiện một số thay đổi và tôi muốn sử dụng một lớp thay vì thee như ví dụ. Tôi đang thêm UISearchController của tôi từ mã. Vấn đề của tôi là tôi không thể gọi UISearchController vì exeption:UISearchController không muốn xuất hiện vì anh ta không có trong hệ thống phân cấp xem

2015-06-18 13:35:04.750 TableSearch[4796:77813] Warning: Attempt to present <UISearchController: 0x7fe09b719f00> on <APLMainTableViewController: 0x7fe09b50e450> whose view is not in the window hierarchy! 

Working project with changes

Có thể ai đó xin vui lòng cho tôi biết những gì tôi đã làm sai? Cảm ơn!

+0

đây là ví dụ đầy đủ http://stackoverflow.com/questions/30851467/implement-uisearchcontroller-with-uitableview/30851918?noredirect=1#comment49749974_30851918 –

+0

Giải pháp là đặt nil trong initWithSearchResultsController! Có câu trả lời của bạn đã giúp hiểu vấn đề, cảm ơn. –

+0

tuyệt vời ................ –

Trả lời

1

Vấn đề là tôi muốn chạy UISearchController:

self.searchController = [[UISearchController alloc] initWithSearchResultsController:self]; 

Giải pháp là để khởi UISearchController:

self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil]; 

và để lại kịch bản như nó đã được.

7

câu trả lời Cập nhật:

self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil]; 

Đối với những người muốn một ví dụ làm việc với kết quả tìm kiếm, xem repo của tôi https://github.com/Optimbyte/IOSVC-master

Cũ câu trả lời: Tôi nghĩ rằng bạn quên thêm vào MainStoryBoard một thanh tìm kiếm và hiển thị tìm kiếm điều khiển. required

+2

có thể là UISearchDisplayController không phải là những gì anh ta muốn? –

+0

Nhưng tôi muốn thêm UISearchController từ mã ... –

+0

Giải pháp là đặt nil trong initWithSearchResultsController! Cảm ơn bạn đã giúp đỡ! –

Các vấn đề liên quan