2012-11-28 59 views
0

我在tableView1的表頭中有2個按鈕。我希望它這樣,當人們點擊任一按鈕,發生兩件事情:有人點擊IOS中的按鈕時隱藏表格視圖

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]; 
} 

但這不起作用。

+0

你能說明你是如何設置myTableView1和myTableView2的嗎? – Ryan

回答

0

有這麼多的可能性實現這樣的UI。

1.Either你可以保持兩個按鈕以外或兩個以上tables.So,如果你點擊按鈕1隱藏第一臺&顯示第二&當點擊第二隱藏第二臺&顯示錶頭。

OR

2.In第一表中添加的第一行作爲你們兩個按鈕did.When你點擊按鈕1,然後,而不是躲在numberofrows方法&重裝表1爲表1的數據源第一個表返回1,使按鈕將出現&然後顯示第一個表下面的第二個表。當用戶單擊第二個按鈕,然後隱藏第二個表&返回第一個表的新數據源&重新加載表1。

OR

3.使用兩個數據一個表source.At第一行會有兩個buttons.On點擊它們重新加載相應表格。

0

您可以使用單個表視圖,只需在單擊按鈕時更改數據源,然後重新加載tableview。

0

您可以設置self.myTableView1.datasource =零,當你需要使用它,你可以設置self.myTableView1.datasource =自我和[self.myTableView1 reloaddata]