2017-06-20 9 views
0

テーブルビュー内のオブジェクトを動的挿入行に追加したいとします。オブジェクトをテーブルビューに追加する

コードは動作していないようですが、行は挿入されていません。

コード:

- (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; 
} 

オブジェクトがtextlabelテキストに追加されていないと、それは新しい行を持っていません。私はこの種のiOSに慣れていないので、コードに何が問題なのですか?

私は多くのことを試みましたが、動作させることはできません。

ありがとうございました。

+0

'それが初期化されself.greekLetters'を?それは 'nil'ですか? – Larme

+0

viewcontroller.hにあります。 @property(コピー、非アトミック)NSMutableArray * greekLetters; – Anoniem

+1

あなたは 'self.greekLetters = [[NSMutableArray alloc] init];'をしました。 – Larme

答えて

0

こんにちはコードの下に見つけてください:

- (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; 
} 
+1

コードを投稿するだけではありません。問題が何であるかを説明し、答えがどのように問題を解決するかを説明します。 – rmaddy

関連する問題