надеюсь, что это поможет
Я взял изменяемый массив и целочисленную переменную и установил общее количество массивов в целочисленную переменную
arr = [[NSMutableArray alloc]initWithObjects:@"Radix",@"Riki", nil];
dataRows = [arr count];
, а затем я установил количество строкв разделах согласно целочисленной переменной в методе источника данных таблицы
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return dataRows+1;
}
, потому что вы хотели добавить дополнительную ячейку в конце.
Теперь пришло время установить текст таблицыячейка
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{статический NSString * CellIdentifier = @ "Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell...
//setting the text of the cell as per Mutable array
if (indexPath.row < [arr count]) {
cell.textLabel.text = [arr objectAtIndex:indexPath.row];
}
//setting the text of the extra cell
if (indexPath.row == dataRows) {
cell.textLabel.text = @"more cells";
}
return cell;
}
теперь при попадании в ячейку больше ячеек, которые вы хотите дополнительные ячейкиПравильно, просто добавьте свой код в метод
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
, что означает, что вы должны сделать что-то вроде этого
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.row == dataRows)
{
//code for exra cells please
}
}
Запустите приложение, чтобы проверить этот код.