セクション分けしたテーブルを使用して、アプリの設定を行う画面を作るときに利用できる。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [self._itemTable dequeueReusableCellWithIdentifier:@"RegularCell"];
if (cell == nil) {
CGRect frame = CGRectMake(0, 0, 300, 44);
cell = [[[UITableViewCell alloc] initWithFrame:frame
reuseIdentifier:@"RegularCell"] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.font = [UIFont systemFontOfSize:14];
}
UISwitch *switchObj = [[UISwitch alloc] initWithFrame:CGRectMake(1.0, 1.0, 20.0, 20.0)];
switchObj.on = NO;
[switchObj addTarget:self
action:@selector(settingSwitch:)
forControlEvents:UIControlEventValueChanged];
cell.accessoryView = switchObj;
[switchObj release];
cell.text = @"設定";
}
テーブルのセクション毎に編集する場合は、
indexPath.section
テーブルセルの行数毎に編集する場合は、
indexPath.rowでif文やswitch文で振分けて編集すること。
タグ:iPhone