2

私は iOS 開発の初心者であり、UITableView の問題に関するヘルプを探しています。

さて、私は UITableView コードに関するすべてを研究していましたが、開発中に識別子を再利用しようとすると (インターフェイスに作成するセルがない場合)、XCode に次のメッセージが表示されます。

「'UITableView' の目に見える @interface はセレクター 'initWithStyle:reuseIdentifier: を宣言しません:」

コードがあります:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *identifier = @"Cell";

    UITableView *cell = [tableView dequeueReusableCellWithIdentifier:identifier];

    if(cell ==nil)
    {
        cell = [[[UITableView alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier] autorelease];
    }

誰かがここで私を助けてくれますか?

4

4 に答える 4

4
UITableView *cell = [tableView dequeueReusableCellWithIdentifier:identifier];

する必要があります

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];

ここで行ったこととは違うものをUITableViewCell 割り当てる必要があります。UITableView

   //should be **UITableViewCell**
      cell = [[[UITableView alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier] autorelease];

後で返却することを忘れないでください。

return cell;
于 2012-07-06T11:37:57.360 に答える
1

エラーメッセージはそれをすべて言います。間違ったクラスでメソッドを呼び出しています...クラスを設定して、UITableViewCell代わりにa を割り当てる必要がありますUITableView

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *identifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];

    if(cell == nil)
    {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier] autorelease];
    }

    // ...
于 2012-07-06T11:37:57.043 に答える
0

私の一日を救った。私のコードを置き換えました-コメントされ、このコードで-そしてそれはうまくいきました。理由はわかりませんが!! しかし、ありがとう。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
//  static NSString *identifier = @"cell";
//  UITableViewCell *cell = [tableView dequeueReusableCellWithIndentifier:@"cell"];

        static NSString *CellIdentifier = @"cell";
        UITableViewCell *cell=(UITableViewCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];


    if (cell == nil ) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        cell.accessoryType = UITableViewCellAccessoryNone;
    }
    return cell;
}
于 2013-10-09T12:29:54.030 に答える
0

コードの代わりに次のコードを使用してください。

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

     static NSString *CellIdentifier = @"Cell";
        UITableViewCell *cell=(UITableViewCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

        if (cell==nil) {
            cell=[[UITableViewCell alloc]initWithFrame:CGRectZero];
        }
于 2012-07-06T11:40:33.380 に答える