0

I want to add a object in my tableview to dynamic insert rows.

The code seems not to be working, no row is inserted.

Code:

- (void)viewDidLoad {
    [super viewDidLoad];

    NSString *newString = @"test!";

    [self.greekLetters addObject:newString];
}

- (NSInteger)tableView:(UITableView *) tableView numberOfRowsInSection:(NSInteger)section {
    return [self.greekLetters count];
}

-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
    NSString *SimpleIdentifier = @"SimpleIdentifier";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SimpleIdentifier];

    if (cell == nil) {
        cell = ([[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:(SimpleIdentifier)]);
    }

    cell.textLabel.text = [NSString stringWithFormat:@"%@", [self.greekLetters objectAtIndex:indexPath.row]];

    cell.detailTextLabel.text = @"Laatste datum";

    return cell;
}

The object isn't adding to the textlabel text and it hasn't a new row. I am new to this sort of iOS, so what's wrong with the code?

I tried many things but can't get it to work.

Thanks.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Anoniem
  • 17
  • 7

1 Answers1

0

Hi please find below code :

- (void)viewDidLoad {
    [super viewDidLoad];

    self.greekLetters = [[NSMutableArray alloc] init];

    NSString *newString = @"test!";

    [self.greekLetters addObject:newString];
}

- (NSInteger)tableView:(UITableView *) tableView numberOfRowsInSection:(NSInteger)section {
    return [self.greekLetters count];
}

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

    NSString *SimpleIdentifier = @"SimpleIdentifier";


    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SimpleIdentifier];

     if (cell == nil) {
         cell = ([[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:(SimpleIdentifier)]);
    }

    cell.textLabel.text = [NSString stringWithFormat:@"%@", [self.greekLetters objectAtIndex:indexPath.row]];

    cell.detailTextLabel.text = @"Laatste datum";


    return cell;
}
rmaddy
  • 314,917
  • 42
  • 532
  • 579
Optimus
  • 800
  • 5
  • 16
  • 1
    Please don't just post code. Explain what the problem was and explain how your answer solves the issue. – rmaddy Jun 20 '17 at 17:29