UITableView的第一行不同

nit*_*hin 1 iphone uitableview uiimage ios

我需要一个UITableView第一行应显示徽标,而其他行应显示其他表数据.我尝试了以下代码:

if(indexPath.row == 0) {
    //Code for imageview
} else {
    //Code to display array content
}
Run Code Online (Sandbox Code Playgroud)

我的问题是我没有得到表视图中的第一个数组项.

编辑::

if (indexPath.row == 0) {

        CGRect myImageRect = CGRectMake(120.0f, 5.0f, 70.0f, 55.0f);
        UIImageView *myImage = [[UIImageView alloc] initWithFrame:myImageRect];
        [myImage setImage:[UIImage imageNamed:@"logo.png"]];
        [cell.contentView addSubview:myImage];
    }
    else  {

       NSDictionary *dict = [menuitems objectAtIndex:indexPath.row];

        cell.textLabel.text =[dict objectForKey:@"category"]; 
       }
Run Code Online (Sandbox Code Playgroud)

Rup*_*esh 8

尝试使用标题视图.使用以下代码将徽标放在行的顶部.

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{

    UIView *myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 50)];
    UIImageView *myimgvw = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 50)];
    [myimgvw setImage:[UIImage imageNamed:@"logo.png"]];
    [myView addSubview:myimgvw];

    return myView; 
}
Run Code Online (Sandbox Code Playgroud)