Reputation: 17
im using core data i have an entity called questions whenever i add my question to my table i want them to display the number of the question (kind of like auto increment thing) can anyone pls help me out thanks
here is my code if its relevant
- (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;
}
Upvotes: 0
Views: 160
Reputation: 6413
- (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;
}
Upvotes: 1