![](/img/trans.png)
[英]iPhone sdk how to set view orientation with two different views displayed by segmented control
[英]iPhone SDK:How to use Segmented to Control two different TableView?
我搜索类似该问题的类似问题是否需要使用分段控件来显示表的方法?
解决方案是使用单个tableview
但是我觉得我的问题有点不同
因为视图将具有分段控件,所以有两个选择:“ DHCP”和“ Manual”
当我按“ DHCP”时,在分段控制器下将有一个分组表
此表视图不可编辑,每行仅显示3个项(IP地址,掩码,路由器)
但是如果按下“手动”,表格视图将变为可编辑状态
只能输入类似第1行的IP Address : 169.95.192.1
“,第2行的Subnet mask 255.255.255.0
” ...
所以我的问题是
<1>如何使用分段控件来切换两个不同的表?
<2>如何创建可编辑的表格视图?
非常感谢您阅读并回答此问题。
对...好-您需要有一个全局BOOL
例如BOOL isManual;
现在,在每个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;
}
}
和类似。
然后在您的分段控制回调方法要更改isManual和reloadData
你的桌子上:
- (void)segmentedControlChanged:(id)selector {
UISegmentedControl *control = selector;
int selected = [control selectedSegmentIndex];
if(selected == 0){
isManual == NO;
}
else{
isManual == YES;
}
[self.tableView reloadData];
}
希望能有所帮助-尽管它含糊不清。 :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.