当有人点击IOS中的按钮时隐藏表格视图

时间:2012-11-28 02:28:54

标签: objective-c ios cocoa-touch ios5 ios4

tableView1的标题中有2个按钮。我想要它,以便当人们点击任一按钮时,会发生两件事:

tableView1消失

tableView2显示

tableView1出现

tableView2消失

我该如何使用IOS?

我尝试了以下操作:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.row == 0)
{
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button setImage: [UIImage imageNamed:@"tableheader_01.png"]forState:UIControlStateNormal];
        button.frame = CGRectMake(0, 0, 159, 57);
        button.tag = 7;
        [button addTarget:self action:@selector(hideTable:) forControlEvents:UIControlEventTouchUpInside];

        UIButton *button2 = [UIButton buttonWithType:UIButtonTypeCustom];
        [button2 setImage: [UIImage imageNamed:@"tableheader_02.png"]forState:UIControlStateNormal];
        button2.frame = CGRectMake(159, 0, 161, 57);
        button2.tag = 7;
        [button2 addTarget:self action:@selector(hideTable:) forControlEvents:UIControlEventTouchUpInside];

        [cell.contentView addSubview: button];
        [cell.contentView addSubview: button2];

hideTable具有以下代码:

-(IBAction) hideTable : (id) sender;
{
    NSLog(@"test");

    [self.myTableView1 setHidden:YES];
    [self.myTableView2 setHidden:NO];
}

但这不起作用。

3 个答案:

答案 0 :(得分:0)

您可以使用单个表视图,只需在单击按钮时更改数据源,然后重新加载tableview。

答案 1 :(得分:0)

你可以设置self.myTableView1.datasource = nil,当你需要使用它时,你可以设置self.myTableView1.datasource = self和[self.myTableView1 reloaddata]

答案 2 :(得分:0)

实现这样的UI有很多可能性。

1.你可以将两个按钮都保持在两个桌子之外或之上。所以,如果你点击button1,你就会隐藏第一个桌子和桌子。展示第二&当点击第二个隐藏第二个表&显示第一张表。

OR

2.在第一个表中,在第一行添加两个按钮。当您单击button1时,而不是隐藏第一个表返回1表示dataofrows方法中的table1数据源&重新加载table1,以便按钮在那里&然后在第一个表格下面显示第二个表格。当用户点击第二个按钮然后隐藏第二个表格&返回第一个表的新数据源&重新加载table1。

OR

3.为两个数据源使用一个表。第一行会有两个按钮。点击它们会相应地重新加载表。