生成多维标签

时间:2015-01-09 06:06:55

标签: objective-c xcode uitableview uibutton

我想设置二维数组,因为我想知道它指示的是哪个单元格,以及该单元格按哪个按钮。我怎样才能实现它?

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

    TimelineTableViewCell *timeLineCell = (TimelineTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if(timeLineCell==nil)
    {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"TimelineTableViewCell" owner:self options:nil];
        timeLineCell = [nib objectAtIndex:0];
    }
    UIScrollView *scrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 45, 600, 100)];
    scrollView.showsHorizontalScrollIndicator=YES;
    scrollView.delegate=self;
    int i=0;
    UIView *v1=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 110*13, 100)];
    for(i=0;i<10;i++)
    {
        UIImageView *imageView1=[[UIImageView alloc]initWithFrame:CGRectMake((i*110),0, 100.0, 100.0)];
        imageView1.image=[UIImage imageNamed:@"alia.png"];
        NSInteger xPos=80+(i*110);
        NSLog(@"xPos:%ld",(long)xPos);
        UIButton *btn1=[[UIButton alloc]init];
        [btn1 setImage:[UIImage imageNamed:@"icon_Cancel@2x.png"] forState:UIControlStateNormal];
        [btn1 setFrame:CGRectMake(xPos, 0, 20, 20)];
        btn1.backgroundColor=[UIColor clearColor];
        [btn1 setTag:i];
        [btn1 addTarget:self action:@selector(cancelEvent:) forControlEvents:UIControlEventTouchUpInside];
        [v1 addSubview:btn1];
        [v1 addSubview:imageView1];

    }

    [scrollView addSubview:v1];
    scrollView.contentSize = v1.frame.size;
    [timeLineCell addSubview:scrollView];

    //set font
    UIFont *font17=[UIFont fontWithName:@"Titillium Web" size:17.0];
    UIFont *font15=[UIFont fontWithName:@"Titillium Web" size:15.0];
    UIFont *font13=[UIFont fontWithName:@"Titillium Web" size:13.0];
    UIFont *font10=[UIFont fontWithName:@"Titillium Web" size:10.0];
    [timeLineCell.lblPostUserName setFont:font17];
    [timeLineCell.lblTime setFont:font13];
    [timeLineCell.lblDate setFont:font13];
    [timeLineCell.lblNoOfLike setFont:font10];
    [timeLineCell.lblNoOfComment setFont:font10];
    [timeLineCell.txtPost setFont:font15];
    /////////////////////////////

    //timeLineCell.image.image=[[UIImage imageNamed:@"back_like_comm@2x.png"]stretchableImageWithLeftCapWidth:5 topCapHeight:5];
    timeLineCell.imgPostUser.layer.cornerRadius=20.0;
    timeLineCell.imgPostUser.layer.masksToBounds=YES;
    timeLineCell.imgPostUser.image=[UIImage imageNamed:@"beuty.png"];

    return timeLineCell;
}

1 个答案:

答案 0 :(得分:0)

子类UIButton并添加一个属性来存储列的标记。检索此值以及正常标记的值以获取行#和col#。类似于this