UITableView中的错误[IRForTarget]

时间:2013-04-01 06:28:26

标签: iphone uitableview

我在视图控制器中拥有的不仅仅是一个表视图,它给出了错误。我不知道任何人都可以指导哪里出错。数据没有显示在表视图中,但是数组在控制台中打印时有数据,我试过没有数组也提供静态数据到cell.textLabel.text,但没有在tableview中显示,行检查的行数没有问题。控制没有去cell.textLabel.text,我没有得到什么错。请指导以上内容。以下是代码:

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

if(tableView == self.mLocationTable)
{
    cell = [self.mLocationTable dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
    else{
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
    // if([self.mLocShowArr count]!= 0)
    // {
    //  NSString *str = [self.mLocShowArr objectAtIndex:indexPath.row];
    cell.textLabel.text = @"locations";
    // NSLog(@"show loc:%@", [self.mLocShowArr objectAtIndex:0]);
    //  }

}

if(tableView == self.mNotifyTable)
{
    cell = [self.mNotifyTable dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
    UIImage *yourImage = [UIImage imageNamed:@"emma-watson-02.jpg"];
    UIImageView *imageViewToPutInCell = [[UIImageView alloc] initWithImage:yourImage];
    imageViewToPutInCell.frame = CGRectMake(5, 8, 55, 55);

    UILabel *cellTextLabel = [[UILabel alloc]initWithFrame:CGRectMake(68, 10, 200, 40)];
    cellTextLabel.text = @"notification view";

    [cell addSubview:imageViewToPutInCell];
    [cell addSubview:cellTextLabel];

}
}

这是完整的错误:错误[IRForTarget]:调用目标中不存在的仅符号函数'objc_msgSend'。

2 个答案:

答案 0 :(得分:0)

要检查的事情。

  1. 所有必需的数据源方法
  2. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 记录返回值并确保它不是0
  3. 为不同的表格提供不同的单元格标识符
  4. 确保表数据源和代理在nib中连接
  5. 错误说明here

答案 1 :(得分:0)

试试这个代码!!!在您的代码中,您错过了“返回单元格”;

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
    cell.selectionStyle = UITableViewCellSelectionStyleBlue;
    cell.accessoryType = UITableViewCellAccessoryNone;
}
    if(tableView == self.mNotifyTable) {
      cell.textLabel.text = @"locations";

      UIImage *yourImage = [UIImage imageNamed:@"emma-watson-02.jpg"];
      UIImageView *imageViewToPutInCell = [[UIImageView alloc] initWithImage:yourImage];
      imageViewToPutInCell.frame = CGRectMake(5, 8, 55, 55);

      UILabel *cellTextLabel = [[UILabel alloc]initWithFrame:CGRectMake(68, 10, 200, 40)];
      cellTextLabel.text = @"notification view";

      [cell addSubview:imageViewToPutInCell];
      [cell addSubview:cellTextLabel];
   }
   return cell;
}

希望这能解决你的问题!!!

如果对你有帮助,请接受答案!