2016-04-10 8 views
0

私はObjective-Cを初めて使い、UITableViewで作業しようとしています。ここで私はエラーを取得する方法は次のとおりです。'UITableViewCell'の表示されない@interfaceは、セレクタ 'dequeueReusableCellWithIdentifier:'を宣言します。

-(UITableViewCell *)tableView:(UITableViewCell *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MainCell"]; 

    if(cell == nil){ 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"MainCell"]; 
    } 
} 

は誰が私を助けてくださいもらえますか?

+0

使用するようにしてくださいする必要がありますそのようなメソッド名を入力するためのXcodeのオートコンプリート機能。これは、このような誤植を避けるのに役立ちます。 – rmaddy

+0

@rmaddyありがとう! –

答えて

3

メソッドのシグネチャが間違っていると一般的に

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

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MainCell"]; 

    if(cell == nil){ 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"MainCell"]; 
    } 
} 
+0

ありがとうございます!できます! –

+0

うれしかったです。受け入れられた答えとしてマークしてください:) –

+0

既に完了しました: –

1

、あなたがそのようなエラーメッセージが表示されたとき、あなたがメッセージを送信するために変数の型を探す必要がありますする必要があります。この場合

、問題は、メソッドのシグネチャを誤って入力していることである:最初のパラメータ型がUITableViewある、ないUITableViewCell

-(UITableViewCell *)tableView:(UITableViewCell *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
//        ^^^^^^^^^^^^^^^ 

これは

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
//        ^^^^^^^^^^^ 
+0

ありがとうございました! –

関連する問題