![](/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.