私のアプリには UITableView があり、2 つの異なるカスタム UITableViewCells があります。UITableView は、最初に 1 種類のカスタム UITableViewCell でロードされます。私のUITableViewでセルの1つが選択されている場合、選択されたセルを他のタイプのカスタムUITableViewCellで変更したいと思います。これは可能ですか?あなたが得たものを聞かせてください。
ありがとう、NSNolan
#pragma mark - UITableView delegate methods
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.array count];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.row == [self currentCellIndex]) {
[self setCurrentCellIndex:-1];
NSArray *nibs = [[NSBundle mainBundle] loadNibNamed:@"NewCell" owner:self options:nil];
OldCell *cell = (OldCell *)[tableView cellForRowAtIndexPath:indexPath];
cell = [nibs objectAtIndex:0];
}
else {
[self setCurrentCellIndex:indexPath.row];
NSArray *nibs = [[NSBundle mainBundle] loadNibNamed:@"NewCell" owner:self options:nil];
NewCell *cell = (NewCell *)[tableView cellForRowAtIndexPath:indexPath];
cell = [nibs objectAtIndex:0];
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"OldCell";
OldCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
NSArray *nibs = [[NSBundle mainBundle] loadNibNamed:@"OldCell" owner:self options:nil];
cell = [nibs objectAtIndex:0];
}
return cell;
}