0
グループ化されたUITableViewを配列に格納しようとしています(つまり、すべての個々のセル)ので、ユーザーがタップしたセルを保持できます。私が試して、セルを復元するたびに、私は表示されている最新のセルで終わる(すなわち、画面の一番下に現れたセルは、スクロールバックの最上部に表示されます。) わかりませんこれを正しく行うには熱いので、任意の助けが おかげグループ化されたUITableViewを配列に格納する
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
MyManager *dataStore = (MyManager*)[MyManager sharedManager];
NSNumber *dif = [[NSNumber alloc] initWithInt:-1];
if (indexPath.section == 0) {
dif = [NSNumber numberWithInt:0];
} else if (indexPath.section == 1) {
dif = [NSNumber numberWithInt:3];
} else if (indexPath.section == 2) {
dif = [NSNumber numberWithInt:5];
} else if (indexPath.section == 3) {
dif = [NSNumber numberWithInt:9];
}
if ([dataStore.masterArray objectAtIndex:(indexPath.row+[dif intValue])][email protected]"0") {
//array is initalised with 16 strings of @"0", just to fill it
static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier";
NSArray *listData =[self.data objectForKey:
[self.sortedKeys objectAtIndex:[indexPath section]]];
UITableViewCell * cell = [tableView
dequeueReusableCellWithIdentifier: SimpleTableIdentifier];
if(cell == nil) {
cell = [[[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:SimpleTableIdentifier] autorelease];
}
NSUInteger Row = [indexPath row];
cell.textLabel.text = [listData objectAtIndex:Row];
cell.accessoryType = UITableViewCellAccessoryNone;
[dataStore.masterArray replaceObjectAtIndex:(indexPath.row + [dif intValue]) withObject:cell];
cell.textLabel.text = [listData objectAtIndex:Row];
cell.accessoryType = UITableViewCellAccessoryNone;
return cell;
}
else {
UITableViewCell *cell = [dataStore.masterArray objectAtIndex:(indexPath.row+[dif intValue])];
return cell;
}
}
非常に歓迎され、私は、これが正常に動作します(何が、その後1を作成し、表示する場合は、このコードは、インデックスのセルがあるかどうかを確認するべきではないことを前提としています)セルが存在する場合は、それを配列から取り出して表示します。
解答がとてもシンプルだったので、私はこの時間を無駄にしていました。ありがとう、魅力のように働いています – Darc
こんにちは、それは新鮮な視点を持つのに役立ちます。お役に立てて嬉しいです。 – drewag