【问题标题】:How to assign values to different IBActions in iOS?如何在 iOS 中为不同的 IBAction 赋值?
【发布时间】:2016-04-26 09:47:45
【问题描述】:

在我的应用程序中,我想根据 IBActions 加载我的单元格。这是我的两个 IBActions,

-(IBAction)action1:(id)sender
{
}

-(IBAction)action2:(id)sender
{
}

我想这样加载

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (value == 0)
{
    return 96;
}
else if(value == 1)
{
    return 237;
}
return 0;
}

如何将 value=0 分配给 action1 并将 value =1 分配给 action2?

【问题讨论】:

  • 其实你想要什么?
  • @IOSDeveloper。如何将我的 value=0 分配给我的 action1 并将 value =1 分配给我的 action2?
  • @User558 你拥有一切......就去做吧。

标签: ios uitableview uibutton


【解决方案1】:
 -(IBAction)action1:(id)sender
  {
    self.value  = 0
    self.tableView.reloadData()
  }

【讨论】:

    【解决方案2】:

    写下代码

    -(IBAction)action1:(id)sender
    { self.value = 0
      self.tableView.reloadData()
    }
    
    -(IBAction)action2:(id)sender
    {
      self.value = 1
      self.tableView.reloadData()
    }
    

    【讨论】:

      【解决方案3】:

      无需创建两个方法即可使用 UIButton 类的 tag 属性

      -(IBAction)action1:(UIButton *)sender
      {
          if (sender.tag == 0)
          {
              self.value = 0;
          }
          else
          {
              self.value = 1;
          }
      
          self.tableView.reloadData()
      }
      

      【讨论】:

        猜你喜欢
        • 2019-03-23
        • 1970-01-01
        • 2011-12-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-12
        • 2015-02-20
        • 1970-01-01
        相关资源
        最近更新 更多