UITableView
デフォルトを選択なし に設定するにはどうすればよいですか? indexPath.row = -1
または似たようなものですか?
テーブルを作成するための私のコードは次のとおりです。
UITableView* tblThisTable = [[UITableView alloc] initWithFrame:CGRectMake(elementX, elementY, elementW, elementH)];
tblThisTable.rowHeight = 30.0;
tblThisTable.layer.borderColor = [colorManager setColor:51.0 :51.0 :51.0].CGColor;
tblThisTable.layer.borderWidth = 1.0;
tblThisTable.delegate = self;
tblThisTable.dataSource = self;
そして、デリゲートプロトコルの私の実装:
#pragma mark - Table View Management
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return arrStates.count;
}
// 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];
}
cell.textLabel.text = [arrStates objectAtIndex:indexPath.row];
cell.textLabel.textColor = [colorManager setColor:66.0 :66.0 :66.0];
cell.textLabel.font = [UIFont fontWithName:@"Helvetica" size:20.0];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
strSelectedState = [arrStates objectAtIndex:indexPath.row];
}
plist に保存する前に、ユーザー エントリの値をチェックするデータ マネージャー クラスがあります。テーブルに関連するコードは次のとおりです(状態テーブルのみがあります):
...
} else if ([[_arrAllElements objectAtIndex:i] isMemberOfClass:[UITableView class]]) {
UITableView* tblThisTable = (UITableView*)[_arrAllElements objectAtIndex:i];
strElementKey = @"State";
int selectedRow = tblThisTable.indexPathForSelectedRow.row;
if(selectedRow > -1) {
strElementValue = [arrStates objectAtIndex:selectedRow];
} else {
strElementValue = @"No Entry";
}
...
したがって、ユーザーがテーブルで何も選択せずに保存ボタンを押すと、selectedRow の値は 0 のままですが、何も選択されていません。UISegementedControls を -1 に設定して選択できないようにすることを考えていました。テーブルも同様にすべきではありませんか?