Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/105.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 将视图添加到UITableViewCell';s contentView,将视图放置在错误的位置_Ios_Uitableview_Ios7_Uitextfield - Fatal编程技术网

Ios 将视图添加到UITableViewCell';s contentView,将视图放置在错误的位置

Ios 将视图添加到UITableViewCell';s contentView,将视图放置在错误的位置,ios,uitableview,ios7,uitextfield,Ios,Uitableview,Ios7,Uitextfield,我似乎在理解子视图如何工作时遇到了问题。我有一个UITextfield,我想将其添加到UITableViewCell的内容视图中,因此我执行以下操作: -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifie

我似乎在理解子视图如何工作时遇到了问题。我有一个
UITextfield
,我想将其添加到
UITableViewCell
的内容视图中,因此我执行以下操作:

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

  UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:nil];

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

    }    // Configure the cell...
    UITextField *tf = [textFieldsArray objectAtIndex:[indexPath row]];
    tf.frame = CGRectMake(0, 0, 100, 12);
    [cell.contentView addSubview:tf];
    return cell;
}
我假设,当我将其作为子视图添加到内容视图时,通过使文本字段框原点(0,0),它会将其放置在内容视图中的位置(0,0),但这并没有发生,它实际上是将其放置在整个单元格(单元格最左上部分)的位置(0,0)

除非在iOS7中对此进行了更改,否则我认为内容视图是这样的:


(来源:)


如果是这样的话,有没有一种方法可以在每次不必手动定义偏移量的情况下将其放入
contentView
中?

除非您处于编辑模式,否则
contentView
的左上角和单元格都是一样的。啊,麦迪,谢谢,我觉得太愚蠢了@泰勒杜登,没关系。有时候,当你看得太久的时候,很难看到显而易见的东西。享受。:)顺便说一句-当您希望回复某人时,请确保在
@
符号之前指定完整的用户名。
     Try This 


       if (cell==nil) 
        {
        cell = [[[UITableViewCell alloc]initWithStyle:
        UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]autorelease];

        UIImageView *img=[[UIImageView alloc]init];
        img.tag=100;
        img.layer.cornerRadius = 3;
        img.layer.masksToBounds = YES;
        [cell addSubview:img];


        UILabel *lbl= [[UILabel alloc]init];
        lbl.backgroundColor= [UIColor clearColor];
        lbl.text=@"ABC";
        lbl.textAlignment=NSTextAlignmentLeft;
        lbl.textColor=[UIColor blackColor];
        lbl.tag=200;
       [cell addSubview:lbl];


     }
img1=(UIImageView *)[cell viewWithTag:100];

NSArray *imgDataArr = [[NSArray alloc] initWithArray:[[arrFields objectAtIndex: storyIndex] objectForKey: @"image"]];

for (UIImage *image in imgDataArr)
{
    if (image)
        img1.image =image;
}
[cell addSubview:img1];


UILabel *lbl1 = (UILabel*)[cell viewWithTag:200];
[cell addSubview:lbl1];
lbl1.numberOfLines=3;
lbl1.text=[[arrFields objectAtIndex: storyIndex] objectForKey: @"Item_No"];