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
But I think my problem is a little different
because the view will have a segmented control,h开发者_运维技巧as two selection: "DHCP" and "Manually"
When I pressed "DHCP",there will be a grouped table under the segmented controller
This tableview is uneditable ,only shows 3 items(IP address,mask,Router)in each rows
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
"...
So my question is
<1>How to use segmented control to switch two different table ?
<2>How to create a editable tableview ?
great thanks for reading and reply this question.
right... well - you need to have a global BOOL
eg BOOL isManual;
now in each of your UITableViewDatasource methods you need to check this bool:
- (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:
- (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. :)
精彩评论