テーブルに5つの個別のセクションがあり、2つのセクションにはカスタマイズ可能なセルがあります。編集モードでは、2つのセクションが追加のセルを生成し、リストに新しいセルを追加します。私の問題は、編集モードを呼び出すと、UISwitch
グリッチが発生することです。そして、非常に単純なコードでジャンプすることにしました。UISwitchが異なるセクションの異なるセルにジャンプするべきではないのになぜジャンプするのかというアイデアはありません。
static NSInteger kCustomTextTag = 1;
static NSInteger kServiceTag = 3;
static NSInteger kConnectTag = 4;
static NSInteger kVibrateTag = 1;
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
Profile_ManagerAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
cell.hidesAccessoryWhenEditing = YES;
}
UISwitch *swService = nil;
swService = [[[UISwitch alloc] initWithFrame:CGRectMake(195, 8, 160, 27)] autorelease];
[swService addTarget:self action:@selector(serviceSwAction:) forControlEvents:UIControlEventValueChanged];
swService.tag = kServiceTag;
UISwitch *swConnect = nil;
swConnect = [[[UISwitch alloc] initWithFrame:CGRectMake(195, 8, 160, 27)] autorelease];
[swConnect addTarget:self action:@selector(connectSwAction:) forControlEvents:UIControlEventValueChanged];
swConnect.tag = kConnectTag;
UISwitch *swVibrate = nil;
swVibrate = [[[UISwitch alloc] initWithFrame:CGRectMake(195, 8, 160, 27)] autorelease];
[swVibrate addTarget:self action:@selector(vibrateSwAction:) forControlEvents:UIControlEventValueChanged];
swVibrate.tag = kVibrateTag;
if(indexPath.section == 0)
{
//CGRectMake Method (x, y, width, height)
custProfileNameLabel = [[[UITextField alloc] initWithFrame:CGRectMake(10, 11, 290, 21)] autorelease];
custProfileNameLabel.tag = kCustomTextTag;
custProfileNameLabel.textAlignment = UITextAlignmentLeft;
[cell.contentView addSubview:custProfileNameLabel];
custProfileNameLabel.backgroundColor = [UIColor clearColor];
custProfileNameLabel.userInteractionEnabled = NO;
custProfileNameLabel.placeholder = @"Custom Profile Name";
custProfileNameLabel.autocapitalizationType = UITextAutocapitalizationTypeWords;
custProfileNameLabel.clearButtonMode = UITextFieldViewModeWhileEditing;
//UIKeyboardTypeDefault;
cell.selectionStyle = UITableViewCellEditingStyleNone;
CustomProfile *cProf = [CustomProfile alloc];
cell.textLabel.text = [cProf tName];
}
if(indexPath.section == 1)
{
if(indexPath.row == ([[appDelegate serviceArray] count]) && self.editing){
cell.textLabel.text = @"Add a Service";
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.accessoryType = UITableViewCellAccessoryNone;
swService.hidden = YES;
return cell;
}else{
swService.hidden = NO;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.accessoryType = UITableViewCellAccessoryNone;
cell.textLabel.text = [[appDelegate serviceArray] objectAtIndex:indexPath.row];
}
[cell addSubview:swService];
}
if(indexPath.section == 2)
{
if(indexPath.row == ([[appDelegate connectArray] count]) && self.editing){
cell.textLabel.text = @"Add a Connection";
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.accessoryType = UITableViewCellAccessoryNone;
swConnect.hidden = YES;
return cell;
}else{
swConnect.hidden = NO;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.accessoryType = UITableViewCellAccessoryNone;
cell.textLabel.text = [[appDelegate connectArray] objectAtIndex:indexPath.row];
}
[cell addSubview:swConnect];
}
if(indexPath.section == 3)
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *myPlistPath = [documentsDirectory stringByAppendingPathComponent:@"ProfileManager.plist"];
NSDictionary *plistDict = [[NSDictionary alloc] initWithContentsOfFile:myPlistPath];
NSString *value;
value = [plistDict objectForKey:@"Custom Ringtone"];
if(indexPath.row == ([[appDelegate ringArray] count]) && self.editing){
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.accessoryType = UITableViewCellAccessoryNone;
}else{
cell.selectionStyle = UITableViewCellSelectionStyleBlue;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
cell.textLabel.text = value;
}
if(indexPath.section == 4)
{
if(indexPath.row == 0 && self.editing)
{
//cell.userInteractionEnabled = NO;
cell.accessoryType = UITableViewCellAccessoryNone;
cell.textLabel.text = @"Vibrate";
swVibrate.hidden = YES;
}else{
swVibrate.hidden = NO;
//cell.accessoryType = UITableViewCellAccessoryNone;
cell.selectionStyle = UITableViewCellSelectionStyleBlue;
cell.textLabel.text = @"Vibrate";
}
[cell.contentView addSubview:swVibrate];
}
return cell;
}