Xcode 分段选项卡IBAction赢得';t传递到cellForRowAtIndexPath

Xcode 分段选项卡IBAction赢得';t传递到cellForRowAtIndexPath,xcode,swift,uitableview,uisegmentedcontrol,Xcode,Swift,Uitableview,Uisegmentedcontrol,我的问题是我的分段控件不会在我的tableView中将信息传递给我的CellForRowatineXpath方法。选择每个选项卡时,我希望我的表视图显示不同的数据 下面是我的一段代码,我认为我的问题源自于此: var parsedDataForTableView : ParseForDetailView? { didSet { self.selectedIndex = (parsedDataForTableView?.tabSelected)! self.

我的问题是我的分段控件不会在我的tableView中将信息传递给我的CellForRowatineXpath方法。选择每个选项卡时,我希望我的表视图显示不同的数据

下面是我的一段代码,我认为我的问题源自于此:

var parsedDataForTableView : ParseForDetailView? {
    didSet {
        self.selectedIndex = (parsedDataForTableView?.tabSelected)!
        self.tableView.rowHeight = (parsedDataForTableView?.tableViewRowHeight)!
        self.tableView.reloadData()


    }
}

var selectedIndex = Int()


override func viewDidLoad() {
    super.viewDidLoad()

    self.parsedDataForTableView = ParseForDetailView(segmentedTabSelected: 0, primaryBarData: self.primaryBarDetails!, secondaryBarData: self.secondaryBarDetails!)
    configureView()
    configureNavigationBarItems()
    setImageShadow()

}

@IBAction func switchBetweenTabs(sender: AnyObject) {

    if segmentControl.selectedSegmentIndex == 0 {
        print("Drinks Selected")
        self.selectedIndex = 0
        print(self.selectedIndex)
        self.parsedDataForTableView = ParseForDetailView(segmentedTabSelected: 0, primaryBarData: self.primaryBarDetails!, secondaryBarData: self.secondaryBarDetails!)
        self.tableView.reloadData()
    }

    if segmentControl.selectedSegmentIndex == 1 {
        print("Entertainment Selected")
        self.selectedIndex = 1
        print(self.selectedIndex)
        self.parsedDataForTableView = ParseForDetailView(segmentedTabSelected: 1, primaryBarData: self.primaryBarDetails!, secondaryBarData: self.secondaryBarDetails!)
        self.tableView.reloadData()
    }

    if segmentControl.selectedSegmentIndex == 2 {
        print("Info Selected")
        self.selectedIndex = 2
        print(self.selectedIndex)
        self.parsedDataForTableView = ParseForDetailView(segmentedTabSelected: 2, primaryBarData: self.primaryBarDetails!, secondaryBarData: self.secondaryBarDetails!)
        self.tableView.reloadData()
    }
}


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

    let cell  = self.tableView.dequeueReusableCellWithIdentifier("detailViewCell") as! DetailViewCell
    print(self.selectedIndex)
    if self.selectedIndex == 0 {

        cell.drinkLabel.text = self.parsedDataForTableView?.drinksArray[indexPath.section][indexPath.row]
        cell.priceLabel.text = self.parsedDataForTableView?.priceArray[indexPath.section][indexPath.row]
        cell.entertainmentLabel.text = ""
    } else if self.selectedIndex == 1 {

        cell.entertainmentLabel.text = self.parsedDataForTableView?.entertainmentString
        cell.drinkLabel.text = ""
        cell.priceLabel.text = ""

    } else if self.selectedIndex == 2 {
       // finish this...
        cell.drinkLabel.text = "Info"
        cell.priceLabel.text = "Info"
        cell.entertainmentLabel.text = "Info"
    }

    return cell
}
在上面,我们将IBAction连接到分段选项卡和CellForRowatineXpath方法。我想将selectedIndex属性传递到cellForRowAtIndexPath方法中,以便在我想显示的不同数据之间切换-在我的didSet top中初始化

当我运行代码时,视图加载正常,第一个段的信息(第0个段索引)显示正确,我的单元格内的打印(self.selectedIndex)按计划打印每个单元格的“0”。当我点击第二个和第三个分段索引时,相同的打印函数不会打印任何内容

当我将IBAction中的信息打印到控制台时,所有内容都在正确更新


为什么只有我的第一个索引使用cellForRowAtIndexPath方法注册

我可能误导了你,让你相信我的问题出在我的逻辑中。我的问题是,在numberOfRowsInSection中,我没有考虑所有三个分段选项卡案例,因此我的数据无法在表视图中正确显示


谢谢@NoName

解析细节视图(segmentedTabSelected:0,primaryBarData:self.primaryBarDetails!,secondaryBarData:self.secondaryBarDetails!)在做什么?这实际上是在更改所选索引吗?此外,每次选择一个新段时,您都会重新加载tableview(这可能不是您的问题,只是注意到了)@非名称ParseForDetailView初始化正在获取存储在primaryBarData和secondaryBarData中的数据,并根据我的UI上分段选项卡上的选定索引对其进行相应的解析。可能会向parsedDataForTableView添加一条打印语句,以确保其正常工作
var parsedDataForTableView:ParseForDetailView?{didSet{self.selectedIndex=(parsedDataForTableView?.tabSelected)!打印(self.selectedIndex)self.tableView.rowHeight=(parsedDataForTableView?.tableView rowHeight)!self.tableView.reloadData()}
@NoName打印(self.selectedIndex)打印正确的分段选项卡索引。如果要设置selectedIndex两次,一次在
选项卡之间的切换中,然后在
parsedDataForTableView
中。试着把它拿出来。