【问题标题】:TableView Index with Button Title带有按钮标题的 TableView 索引
【发布时间】:2017-10-02 16:34:23
【问题描述】:

我有两个表视图 TableView1、TableView2。 TableView1 包含一个按钮列表,当我单击任何按钮时,TableView2 将出现一个数字列表。

现在,当我选择任何数字时,该数字需要显示在单击的按钮中。

由于我是 IOS 新手,任何人都可以帮助我解决一些逻辑问题吗?

btn_select=[[UIButton alloc]init];
        btn_select.frame=CGRectMake([UIScreen mainScreen].bounds.size.width-245,10,55, 27);
        btn_select.layer.cornerRadius=5;
        btn_select.backgroundColor=[UIColor orangeColor];
        [btn_select addTarget:self action:@selector(NumberButtonclicke:) forControlEvents:UIControlEventTouchUpInside];
        btn_select.tag=indexPath.row;
        [btn_select.titleLabel setTextAlignment:NSTextAlignmentCenter];
        [btn_select setTitle:@"1" forState:UIControlStateNormal];
        [cell addSubview:btn_select];

-(void)NumberButtonclicke:(UIButton *)Sender
{

}

【问题讨论】:

    标签: ios iphone uitableview uibutton tableview


    【解决方案1】:
    -(void)NumberButtonclicke:(UIButton *)Sender
    {
       CGPoint buttonPosition = [sender convertPoint:CGPointZero toView: Yourtableview];
       NSIndexPath *indexPath = [Yourtableview indexPathForRowAtPoint:buttonPosition];
       NSString *str = [Yourarary objectAtIndex:indexPath.row];  // Your Number list
       NSLog(@"Number is ---%@", str)
    
     }
    

    【讨论】:

    • number.text=[NSString stringWithFormat:@"%ld",(long)indexPath.row+1];我不必马上服用。
    • 如果没有数组。您的代码它将作为行号给出您将选择的行
    • 当我点击在数字表视图中的 indexpath 处选择行时,点击按钮文本需要更改为点击的索引号
    • [你的按钮 setTitle:number.text forState:UIControlStateNormal];
    • 所有按钮都在改变我已经尝试过这个我只需要点击按钮来改变
    【解决方案2】:

    您可能只需要一个 tableView,点击时可以折叠和展开 Section。

    这是重复的答案:Expand/collapse section in UITableView in iOS

    在选择行时,在重新加载表格时更改了节标题

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-04-11
      • 1970-01-01
      • 2017-11-13
      • 1970-01-01
      • 2018-07-09
      • 2017-07-01
      • 2013-11-25
      相关资源
      最近更新 更多