iOS,自定义表视图

iOS,自定义表视图,ios,arrays,image,tableview,Ios,Arrays,Image,Tableview,我需要在同一张图片中绘制一个表视图: 我需要向cellforrowatinexpath方法添加什么?因为我创建了包含数据的NSArray,但它显示为一个列表: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableView

我需要在同一张图片中绘制一个表视图:

我需要向
cellforrowatinexpath
方法添加什么?因为我创建了包含数据的
NSArray
,但它显示为一个列表:

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

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        cell.textLabel.font = [UIFont systemFontOfSize:15];
        //cell.textLabel.textAlignment = UITextAlignmentCenter;
    }

    cell.textLabel.text =[list objectAtIndex:indexPath.row];


    cell.textLabel.textColor = [UIColor colorWithRed:0.255 green:0.239 blue:0.239 alpha:1];;

    UITableViewCell *cell1 = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    cell1.textLabel.text =[list objectAtIndex:indexPath.row];
    cell1.textLabel.textColor = [UIColor colorWithRed:0.255 green:0.239 blue:0.239 alpha:1];;


    UIView * v = [[UIView alloc] init];
    v.backgroundColor = [UIColor grayColor];
    cell.selectedBackgroundView = v;


    return cell;


}

据我所知,您希望显示一个datagrid(来自您提供的图片),这在iOS中无法快速/良好地完成

最糟糕的方法是自定义UITableViewCell,使1个单元格=1行,并尝试使所有内容都在其应渲染的位置进行渲染


使用UICollectionView是一条很好但很长的路。您需要自定义流布局,这将非常耗时。

您应该将UITableViewCell->CustomCell子类化

CustomCell.h->添加一些字符串属性(姓名、地址、电话、id) ->添加一些标签(UILabel*lblName、lblAddr、, lblPhone,lblid)

CustomCell.m->@synthetic属性

创建网格的图像并将其加载到表格后面 使桌子透明 使细胞透明

基本上就是这样,如果您想在nib中创建单元格,唯一的问题是控件应该比IBOutlets更大,并且您不会有

    if (cell == nil) {
        cell = [[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        cell.lblName = [UILabel alloc] initWithFrame:(CGRectMake(x,y,w,h)) // enter values to correspond with your picture
        //... do the same for other controls in your custom cell
        //cell.textLabel.textAlignment = UITextAlignmentCenter;
    }

块,因为它将从xib加载…

请显示您的代码输出查看
    if (cell == nil) {
        cell = [[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        cell.lblName = [UILabel alloc] initWithFrame:(CGRectMake(x,y,w,h)) // enter values to correspond with your picture
        //... do the same for other controls in your custom cell
        //cell.textLabel.textAlignment = UITextAlignmentCenter;
    }