я хочу нумеровать свои строки в UITableView - PullRequest
0 голосов
/ 28 февраля 2012

я использую базовые данные. У меня есть объект, называемый вопросами, всякий раз, когда я добавляю свой вопрос в свою таблицу, я хочу, чтобы он отображал номер вопроса (вроде автоматического увеличения), может кто-нибудь, пожалуйста, поможет мне, спасибо

вот мой код, если он уместен

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
 {

// Return the number of sections.
return 1;
  }

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
 {

    // Return the number of rows in the section.
     return [self.questionArray count];
  }

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  {


UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];


// Configure the cell...

questionObject = [self.questionArray objectAtIndex:indexPath.row];

cell.textLabel.text = questionObject.questionDescription;


return cell;
}

1 Ответ

1 голос
/ 28 февраля 2012
 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{


    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (nil == cell) {
      cell = ...; //create a cell instance if it wasn't found in reusable cache
    }

    // Configure the cell...

    questionObject = [self.questionArray objectAtIndex:indexPath.row];

    NSString *cellText = [NSString stringWithFormat:@"%d. %@", indexPath.row+1, questionObject.questionDescription];
    cell.textLabel.text = cellText;


    return cell;
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...