0

前もって感謝します。私のアプリでは、2つの異なるスタイルのカスタムセルを使用する必要があるテーブルビューがあり、2つのカスタムセルを作成し、tableView cellForRowAtIndexPathメソッドでセルに2つの識別子を使用しましたが、2つのセクションを試しました。しかし、それは機能していません。「EXE BAD Excess」または他の種類のエラーが表示されます。以下は私のコードです。

エラー : thread1_EXE_BAD_Access(コード = 2 、アドレス 0 x 0)

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

//CatIdentifier
static NSString *CellIdentiFier = @"CatIdentifier";
static NSString *Cell1IdentiFier = @"CatIdentifier1";

if (indexPath.section == 0)
{
   CommitteCell *cell = ( CommitteCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentiFier];

    if(cell == nil)
    {

       cell = ( CommitteCell *)[[[NSBundle mainBundle] loadNibNamed:@"CommitteeCell" owner:self options:nil] objectAtIndex:0];

    }

    if (indicator == 1)
    {
      cell.lblName.text = str;

    }
    else
    {
      cell.lblName.text = [arrayName objectAtIndex:indexPath.row];
      cell.lblPost.text = [arrayPost objectAtIndex:indexPath.row];
      cell.picimg.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[arrayimage objectAtIndex:indexPath.row]]]];

    }

    cell.backgroundView = [[UIImageView alloc]init];

    UIImage *img  = [UIImage imageNamed:@"link-bg 2.png"];

    ((UIImageView *)cell.backgroundView).image = img;


    return cell;
}


else 
{
    Committee2Cell *cell1 = (Committee2Cell  *)[tableView dequeueReusableCellWithIdentifier:Cell1IdentiFier];
    if(cell1 == nil)
    {

        cell1 = (Committee2Cell  *)[[[NSBundle mainBundle] loadNibNamed:@"Committee2Cell" owner:self options:nil] objectAtIndex:0];

    }

    cell1.lblPost1.text = strPost;
    cell1.txtName.text = strName;


    cell1.backgroundView = [[UIImageView alloc]init];

    UIImage *img  = [UIImage imageNamed:@"link-bg 2.png"];

    ((UIImageView *)cell1.backgroundView).image = img;

    return cell1;
 }

}

tableview の section と section メソッドの行は次のとおりです。

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
 return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
 switch (section)
 {
    case 0:
        return [arrayName count]-1;
        break;
    case 1:
        return 1;
        break;
    default:
        break;
  }

  return 0;
 }

だれかが私の間違いを指摘できるならお願いします。再度、感謝します。

配列とラベルのデータは以下の通りです。

-(void)NewsParser:(NSMutableDictionary *)dic { NSLog(@"dic = %@",dic);

  arrayName = [[NSMutableArray alloc]init];
  arrayPost = [[NSMutableArray alloc]init];
  arrayimage= [[NSMutableArray alloc]init];

  strPost = [[NSString alloc]init];
  strName = [[NSString alloc]init];

  strPost = [[dic valueForKey:@"post"]objectAtIndex:8];
  strName = [[dic valueForKey:@"name"]objectAtIndex:8];

  NSLog(@"Name = %@",strName);
  NSLog(@"Post = %@",strPost);


  for(int i=0;i<[dic count]-1;i++)
  {
    [arrayName addObject:[[dic valueForKey:@"name"]objectAtIndex:i]];
    [arrayPost addObject:[[dic valueForKey:@"post"]objectAtIndex:i]];
    [arrayimage addObject:[[dic valueForKey:@"pic"]objectAtIndex:i]];
  }

  NSLog(@"array  = %@",arrayName);
  NSLog(@"array  = %@",arrayPost);
  NSLog(@"array  = %@",arrayimage);

  [table1 reloadData];


}
4

4 に答える 4

0

さらにヘルプが必要な場合は、私のコードでスムーズに動作するように使用してください。

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if(YOUR CONDITION HERE)
       ShareActionViewCell *shareCell;
        NSString *ShareCellId = [NSString stringWithFormat:@"ShareCell%d",indexPath.row];
        shareCell = (ShareActionViewCell *)[tableView dequeueReusableCellWithIdentifier:ShareCellId];
        if(!shareCell) {
            shareCell = [[ShareActionViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ShareCellId];
        }
        shareCell.selectionStyle = UITableViewCellSelectionStyleNone;
        shareCell.ShareTitle.text = [NSString stringWithFormat:@"%@",[tbldata objectAtIndex:indexPath.row]];


    } else {

        CustCell *dataCell;
        NSString *DataCellId = [NSString stringWithFormat:@"DataCell%d",indexPath.row];
        dataCell = (CustCell *)[tableView dequeueReusableCellWithIdentifier:DataCellId];
        if(!dataCell) {
            dataCell = [[CustCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:DataCellId];
        }
        shareCell.selectionStyle = UITableViewCellSelectionStyleNone;
        shareCell.ShareTitle.text = [NSString stringWithFormat:@"%@",[tbldata objectAtIndex:indexPath.row]];

}
}
于 2013-07-17T14:07:05.200 に答える
0

再利用可能な識別子を一度だけ作成します。このようなことをしてください:

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

       static NSString* identifier;
    if(indexPath.section == 0)
        identifier = @"0";
    else
        identifier = @"1";

   self.tableView.dataSource = self;

    UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:identifier];

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

if (indexPath.section == 0)
{

    if(cell == nil)
    {

       cell = ( CommitteCell *)[[[NSBundle mainBundle] loadNibNamed:@"CommitteeCell" owner:self options:nil] objectAtIndex:0];

    }

    if (indicator == 1)
    {
      cell.lblName.text = str;

    }
    else
    {
      cell.lblName.text = [arrayName objectAtIndex:indexPath.row];
      cell.lblPost.text = [arrayPost objectAtIndex:indexPath.row];
      cell.picimg.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[arrayimage objectAtIndex:indexPath.row]]]];

    }

    cell.backgroundView = [[UIImageView alloc]init];

    UIImage *img  = [UIImage imageNamed:@"link-bg 2.png"];

    ((UIImageView *)cell.backgroundView).image = img;


    return cell;
}
于 2013-07-17T09:27:48.750 に答える