UITableViewStyleGrouped 樣式的TableView 適合用于應(yīng)用程序的屬性設(shè)置:
這樣的TableView 與普通的TableView 在程序設(shè)計(jì)上沒有什么差別。只是在- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 方法中處理各個(gè)單元時(shí)需要逐個(gè)對(duì)單元進(jìn)行處理。代碼:
@interface RootViewController : UITableViewController<UIPickerViewDelegate,UIPickerViewDataSource> {
UISlider *musicVolumnControl;
UISlider *gameVolumnControl;
UISegmentedControl *difficultyControl;
UISlider *shipStablilityControl;
UISwitch *badGuyControl;
UISwitch *debugControl;
UITextField *versionControl;
}
@end
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 4;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
if(indexPath.section ==3)
return 260;
return 45;
}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
switch(section){
case 0:
return 3;
break;
case 1:
return 1;
case 2:
return 1;
case 3:
return 1;
}
return 0;
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
switch([indexPath indexAtPosition:0]){
case 0:
switch([indexPath indexAtPosition:1]){
case 0:
musicVolumnControl = [[UISlider alloc]initWithFrame:CGRectMake(170, 0, 125, 50)];
musicVolumnControl.minimumValue = 0.0;
musicVolumnControl.maximumValue = 10.0;
musicVolumnControl.value = 3.5;
[cell addSubview:musicVolumnControl];
cell.textLabel.text = @"Music Volumn";
break;
case 1:
gameVolumnControl = [[UISlider alloc]initWithFrame:CGRectMake(170, 0, 125, 50)];
gameVolumnControl.minimumValue = 0.0;
gameVolumnControl.maximumValue = 10.0;
gameVolumnControl.value = 3.5;
[cell addSubview:gameVolumnControl];
cell.textLabel.text = @"Game Volumn";
break;
case 2:
difficultyControl = [[UISegmentedControl alloc]initWithFrame:CGRectMake(170, 5, 125, 35)];
[difficultyControl insertSegmentWithTitle:@"Easy" atIndex:0 animated:NO];
[difficultyControl insertSegmentWithTitle:@"Hard" atIndex:1 animated:NO];
difficultyControl.selectedSegmentIndex = 0;
[cell addSubview:difficultyControl];
cell.textLabel.text = @"Difficulty";
break;
}
break;
case 1:
switch([indexPath indexAtPosition:1]){
case 0:
shipStablilityControl = [[UISlider alloc]initWithFrame:CGRectMake(170, 0, 125, 50)];
shipStablilityControl.minimumValue =0.0;
shipStablilityControl.maximumValue = 10.0;
shipStablilityControl.value = 3.5;
[cell addSubview:shipStablilityControl];
cell.textLabel.text = @"Ship Stability";
break;
case 1:
badGuyControl = [[UISwitch alloc]initWithFrame:CGRectMake(200, 10, 0, 0)];
badGuyControl.on = YES;
[cell addSubview:badGuyControl];
cell.textLabel.text = @"Bad Guys";
break;
case 2:
debugControl = [[UISwitch alloc]initWithFrame:CGRectMake(200, 10, 0, 0)];
debugControl.on = YES;
[cell addSubview:debugControl];
cell.textLabel.text = @"Debug";
break;
}
break;
case 2:
versionControl = [[UITextField alloc]initWithFrame:CGRectMake(170, 10, 125, 38)];
//versionControl = [[UITextField alloc]initWithFrame:CGR
versionControl.text = @"1.0.0 Rev. B";
[cell addSubview:versionControl];
cell.textLabel.text = @"Version";
break;
case 3:
picker = [[UIPickerView alloc] initWithFrame:CGRectMake(10, 20, 200, 50)];
//CGSize pickerSize = [picker sizeThatFits:CGSizeZero];
//picker.frame = [self pickerFrameWithSize:pickerSize];
cellCategories = [[NSMutableArray alloc]initWithObjects:@"line 1",@"Line 2",@"Line 3",@"Line 4",@"Line 5",@"Line 6",nil];
picker.delegate = self;
picker.dataSource = self;
picker.showsSelectionIndicator = YES;
picker.multipleTouchEnabled = YES;
picker.userInteractionEnabled = YES;
//[picker becomeFirstResponder];
[cell addSubview:picker];
cell.textLabel.text = @"Picker";
break;
}
}
// Configure the cell.
return cell;
}
|