简体   繁体   English

iPhone SDK:如何使用分段控制两个不同的TableView?

[英]iPhone SDK:How to use Segmented to Control two different TableView?

I search some Similar question like this question Need approach to show tables using segmented control? 我搜索类似该问题的类似问题是否需要使用分段控件来显示表的方法?

the solution is using single tableview 解决方案是使用单个tableview

But I think my problem is a little different 但是我觉得我的问题有点不同

because the view will have a segmented control,has two selection: "DHCP" and "Manually" 因为视图将具有分段控件,所以有两个选择:“ DHCP”和“ Manual”

When I pressed "DHCP",there will be a grouped table under the segmented controller 当我按“ DHCP”时,在分段控制器下将有一个分组表

This tableview is uneditable ,only shows 3 items(IP address,mask,Router)in each rows 此表视图不可编辑,每行仅显示3个项(IP地址,掩码,路由器)

But if pressed "Manually",the tableview will become editable 但是如果按下“手动”,表格视图将变为可编辑状态

Only can type like row 1" IP Address : 169.95.192.1 ",row 2 " Subnet mask 255.255.255.0 "... 只能输入类似第1行的IP Address : 169.95.192.1 “,第2行的Subnet mask 255.255.255.0 ” ...

So my question is 所以我的问题是

<1>How to use segmented control to switch two different table ? <1>如何使用分段控件来切换两个不同的表?

<2>How to create a editable tableview ? <2>如何创建可编辑的表格视图?

great thanks for reading and reply this question. 非常感谢您阅读并回答此问题。

right... well - you need to have a global BOOL eg BOOL isManual; 对...好-您需要有一个全局BOOL例如BOOL isManual;

now in each of your UITableViewDatasource methods you need to check this bool: 现在,在每个UITableViewDatasource方法中,您需要检查以下布尔值:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
    }

    if(isManual){
        // set cell content for manual
    }
    else{
        //set cell content for DCHP
    }

    return cell;
}

// this function allows you to set a table view cell as editable
// look up UITableView delegate methods for more :)
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    if(isManual){
        return YES;
    }
    else{
        return NO;
    }
}

And similar. 和类似。

Then in your segmented control callback method you want to change isManual and reloadData on your table: 然后在您的分段控制回调方法要更改isManual和reloadData你的桌子上:

- (void)segmentedControlChanged:(id)selector {
    UISegmentedControl *control = selector;
    int selected = [control selectedSegmentIndex];

    if(selected == 0){
            isManual == NO;
        }
        else{
            isManual == YES;
        }
    [self.tableView reloadData];
}

Hope that helps somewhat - although its rather vague. 希望能有所帮助-尽管它含糊不清。 :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM