Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/114.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios Swift UITableView在加载后消失_Ios_Swift_Uitableview - Fatal编程技术网

Ios Swift UITableView在加载后消失

Ios Swift UITableView在加载后消失,ios,swift,uitableview,Ios,Swift,Uitableview,我目前遇到一个问题,当我通过IB创建UITableView并显示它时。UITableView一开始加载良好,它显示我的4个单元格,然后立即消失 我相信tableview正在消失,因为容器视图的背景可以更改并且仍然存在 点击嵌入到UINavigationBar中的UISearchBar后,我正在从故事板加载UITableView。 然后我把它插入一个容器中。然后,容器将显示在带有UITableView的屏幕上 它的名称如下所示: var searchFestivalTableViewContain

我目前遇到一个问题,当我通过IB创建UITableView并显示它时。UITableView一开始加载良好,它显示我的4个单元格,然后立即消失

我相信tableview正在消失,因为容器视图的背景可以更改并且仍然存在

点击嵌入到UINavigationBar中的UISearchBar后,我正在从故事板加载UITableView。 然后我把它插入一个容器中。然后,容器将显示在带有UITableView的屏幕上

它的名称如下所示:

var searchFestivalTableViewContainer: UIView?

func searchBarTextDidBeginEditing(searchBar: UISearchBar) {
    showSearchView()
}

func showSearchView() {

    searchBar.showsCancelButton = true

    let storyboard = UIStoryboard(name: "Main", bundle: nil)

    // Setup the festival search controller inside the container

    searchFestivalTableViewContainer = UIView(frame: CGRectMake(0, 64, UIScreen.mainScreen().bounds.width, (UIScreen.mainScreen().bounds.height-64)))
    searchFestivalTableViewContainer!.backgroundColor = UIColor.clearColor()


    let searchFestivalTableController = storyboard.instantiateViewControllerWithIdentifier("searchFestivalTableViewController") as? searchFestivalTableViewController

    searchFestivalTableController!.festivalList = allFestivals!

    searchFestivalTableViewContainer!.addSubview(searchFestivalTableController!.view)

    self.view.addSubview(searchFestivalTableViewContainer!)

}
该类的代码为:

class searchFestivalTableViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {

var festivalList: [Festival]?

struct Objects {
    var sectionName : String!
    var sectionObjects : [Festival]!
}

var allFestivals = [Objects]()

@IBOutlet weak var tableView: UITableView!

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

override func viewDidLoad() {
    super.viewDidLoad()

    allFestivals = getFestivals()

    tableView.reloadData()

}

func getFestivals() -> Array<Objects> {

    var festivalSearchResult  = [String: Array<Festival>]()

    festivalSearchResult["Results"] = [Festival(// Hiding data structure)]

    var objectArray = [Objects]()

    for festival in festivalList! {

        festivalSearchResult["Results"]!.append(festival)

    }

    let sortedFestivals = festivalSearchResult.sort { $0.0 < $1.0 }

    for (key, value) in sortedFestivals {
        objectArray.append(Objects(sectionName: key, sectionObjects: value))
    }


    return objectArray
}



func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    return allFestivals.count
}

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return allFestivals[section].sectionObjects.count
}

func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {

    let sectionHeader = allFestivals[section].sectionName

    return sectionHeader

}


func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

        let festivalInfo = allFestivals[indexPath.section].sectionObjects[indexPath.row]

        let cell = tableView.dequeueReusableCellWithIdentifier("searchFestivalTableCell", forIndexPath: indexPath) as! searchFestivalTableViewCell

        cell.textLabel?.text = festivalInfo.festivalName

        return cell


    }


    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

        // Nothing to do here yet

    }

}

class searchFestivalTableViewCell: UITableViewCell  {

    override func awakeFromNib() {
        super.awakeFromNib()
    }

    func setSelected(selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
    }
}
类SearchFestival AltableViewController:UIViewController、UITableViewDelegate、UITableViewDataSource{
var FesticalList:[节日]?
结构对象{
var sectionName:String!
var sectionObjects:[节日]!
}
var allfestival=[Objects]()
@IBVAR表格视图:UITableView!
重写函数didReceiveMemoryWarning(){
超级。我收到了记忆警告()
//处置所有可以重新创建的资源。
}
重写func viewDidLoad(){
super.viewDidLoad()
AllFestival=getFestival()
tableView.reloadData()
}
func getfestions()->数组{
var festivalSearchResult=[String:Array]()
Festival SearchResult[“结果”]=[Festival(//隐藏数据结构)]
var objectArray=[Objects]()
在节日里庆祝节日{
节日搜索结果[“结果”!。附加(节日)
}
让sortedFestivals=festivalSearchResult.sort{$0.0<$1.0}
对于sortedFestivals中的(键、值){
append(对象(sectionName:key,sectionObjects:value))
}
返回对象数组
}
func numberOfSectionsInTableView(tableView:UITableView)->Int{
返回allfestival.count
}
func tableView(tableView:UITableView,numberofrowsinssection:Int)->Int{
返回所有节日[section].sectionObjects.count
}
func tableView(tableView:UITableView,titleForHeaderInSection:Int)->String{
让sectionHeader=AllFestival[section].sectionName
返回段标题
}
func tableView(tableView:UITableView,cellForRowAtIndexPath:nsindepath)->UITableView单元格{
让festival-alinfo=allfestival[indexPath.section].sectionObjects[indexPath.row]
将cell=tableView.dequeueReusableCellWithIdentifier(“SearchFestival-AltableCell”,forIndexPath:indexPath)设为!SearchFestival-AltableViewCell
cell.textLabel?.text=Festival-Info.Festival-Name
返回单元
}
func tableView(tableView:UITableView,didSelectRowAtIndexPath:nsindepath){
//这里还没什么事可做
}
}
类SearchFestival AltableViewCell:UITableViewCell{
重写func awakeFromNib(){
super.awakeFromNib()
}
func setSelected(选定:布尔,动画:布尔){
super.setSelected(选定,动画:动画)
}
}
这是tableview闪烁并消失后的电流输出

你能帮我解释一下为什么tableview正在运行吗? 控制台中没有错误或信息


谢谢

我认为在您将其
视图作为
子视图添加之前,您应该先将SearchFestival AltableViewController作为
子视图添加到第一个
视图控制器中。虽然不确定,但这是我努力实现它的方式。更多信息请点击此处:

我认为在将其
视图作为
子视图添加之前,您应该先将SearchFestival AltableViewController作为
子视图添加到第一个
视图控制器
。虽然不确定,但这是我努力实现它的方式。更多信息请点击此处:

如果您似乎有一个UIViewController,那么您应该改用UITableViewController,因为它包含了您一开始就需要的所有内容


但是,要解决您的问题,请尝试设置tableView.dataSource=self和tableView.delegate=self

如果您似乎有一个UIViewController,则应改用UITableViewController,因为它包含了您一开始需要的所有内容


但是,要解决您的问题,请尝试设置tableView.dataSource=self和tableView.delegate=self

不完全确定您在做什么,但我通过添加

override func viewWillAppear(animated: Bool) {

    self.tableView.reloadData()


}

不完全确定您正在做什么,但我通过添加解决了一个类似的问题

override func viewWillAppear(animated: Bool) {

    self.tableView.reloadData()


}

你完全正确。如果您不这样做,视图控制器将不会知道它的视图正在被另一个控制器调整大小和处理,并且仍然会尝试调整框架并定位它。太棒了!这实现了一个梦想。self.addChildViewController(SearchFestival AltableController!)self.view.addSubview(SearchFestival AltableViewContainer!)您完全正确。如果您不这样做,视图控制器将不会知道它的视图正在被另一个控制器调整大小和处理,并且仍然会尝试调整框架并定位它。太棒了!这实现了一个梦想。self.addChildViewController(searchFestival-AltableController!)self.view.addSubview(searchFestival-AltableViewContainer!)哦,你的汉堡包菜单图标可能很奇怪,因为你没有包含它的
@2x
@3x
版本。你应该在你的项目中包括这一点,以获得正确的大小。感谢你的输入,我已经通过代码和IB尝试了dataSource和delegate,但没有成功。此外,汉堡包在设备上看起来不错,我只是在上传之前调整了屏幕截图的大小:)哦,你的汉堡包菜单图标可能很奇怪,因为你没有包含它的
@2x
@3x
版本。你应该在你的项目中包括这一点,以获得正确的大小。感谢你的输入,我已经通过代码和IB尝试了dataSource和delegate,但没有成功。此外,汉堡包在设备上看起来不错,我只是在上传之前调整了屏幕截图的大小