Я новичок в разработке iOS.Я пытаюсь добавить два переключателя в таблицу программным способом, используя следующий код -
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
if(indexPath.section== 0){
fooddrinkSettingSwitch=[[[UISwitch alloc] initWithFrame:CGRectZero] autorelease];
[fooddrinkSettingSwitch addTarget:self action:@selector(preferenceSettingAction:) forControlEvents:UIControlEventValueChanged];
[cell addSubview:fooddrinkSettingSwitch];
cell.accessoryView = fooddrinkSettingSwitch;
apparelSettingSwitch=[[[UISwitch alloc] initWithFrame:CGRectZero] autorelease];
[apparelSettingSwitch addTarget:self action:@selector(preferenceSettingAction:) forControlEvents:UIControlEventValueChanged];
[cell addSubview:apparelSettingSwitch];
cell.accessoryView = apparelSettingSwitch;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
//get the dictionary object
NSDictionary *dictionary = [listOfItems objectAtIndex:indexPath.section];
NSArray *array = [dictionary objectForKey:@"SettingTitle"];
NSString *cellValue = [array objectAtIndex:indexPath.row];
cell.textLabel.text = cellValue;
return cell;
}
Однако он отображает Food & Drink в качестве переключателя и Apparel в качестве ссылки.Что я делаю не так?