0

webi7、webi5、webi2 は、ユーザーが私のアップロードした動画を気に入ったことを示しています。これらはすべてボタンです。私の動画を気に入った 10 人または 1 人のユーザーの名前である可能性があります。

uibutton を追加したい。そのユーザーボタンをクリックすると、instagramアプリと同じ詳細画面が表示されます。

現在、ios 6.0 では問題なく動作していますが、5.0 でクラッシュします。

これが私のテーブルのカスタムセルコードです:

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    VideoListCustomCell *cell = (VideoListCustomCell *)[self.tableView dequeueReusableCellWithIdentifier:@"VideoListCustomCell"];
    //if(cell == nil)    {
        NSArray* nib = [[NSBundle mainBundle] loadNibNamed:@"VideoListCustomCell" owner:self options:nil];
        cell = [nib objectAtIndex:0];
        cell.showsReorderControl = NO;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.backgroundColor=[UIColor clearColor];
        [cell drawImageView];

        [cell.btnLike addTarget:self action:@selector(btnLikeClick:) forControlEvents:UIControlEventTouchUpInside];
        [cell.btnComment addTarget:self action:@selector(btnCommentClick:) forControlEvents:UIControlEventTouchUpInside];
        [cell.btnOther addTarget:self action:@selector(btnOtherClick:) forControlEvents:UIControlEventTouchUpInside];
        [cell.btnUserImage addTarget:self action:@selector(btnUserImageClick:) forControlEvents:UIControlEventTouchUpInside];
        [cell.btnUserName addTarget:self action:@selector(btnUserNameClick:) forControlEvents:UIControlEventTouchUpInside];
        [cell.btnVideo addTarget:self action:@selector(btnVideoClick:) forControlEvents:UIControlEventTouchUpInside];
    //}

    VideoShare *shareObj = [arrVideos objectAtIndex:indexPath.row];

    [cell.btnUserName setTitle:shareObj.vdUserName forState:UIControlStateNormal];
    cell.btnUserImage.imageURL = [NSURL URLWithString:shareObj.vdUserPhotoUrl];
    cell.btnVideoThumbnail.imageURL = [NSURL URLWithString:shareObj.vdThumbUrl];
    cell.lblTimeUpload.text=shareObj.vdTimeUpload;

    cell.btnComment.tag = shareObj.vdId;
    cell.btnLike.tag = indexPath.row;
    cell.btnOther.tag = indexPath.row;
    cell.btnUserImage.tag = shareObj.vdUserId;
    cell.btnUserName.tag = shareObj.vdUserId;
    cell.btnVideo.tag = indexPath.row;

    int posx = 18;
    int posy = 0;

    if (shareObj.vdLoginUserLikeOrNot == 1) {
        [cell.btnLike setTitle:@"Liked" forState:UIControlStateNormal];
    }
    else {
        [cell.btnLike setTitle:@"Like" forState:UIControlStateNormal];
    }

    if ([shareObj.vdLikeUserDetail count] == 0) {
        cell.imgLikeSymbol.hidden = YES;
    }
    else if ([shareObj.vdLikeUserDetail count] > 4) {
        cell.imgLikeSymbol.hidden = NO;

        UIButton *btnLikeUserCount = [UIButton buttonWithType:UIButtonTypeCustom];
        [btnLikeUserCount.titleLabel setFont:[UIFont boldSystemFontOfSize:13]];
        btnLikeUserCount.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        btnLikeUserCount.frame = CGRectMake(posx,posy,200,16);
        btnLikeUserCount.tag = shareObj.vdId;
        [btnLikeUserCount setTitle:[NSString stringWithFormat:@"%d likes",shareObj.vdLikeCount] forState:UIControlStateNormal];
        [btnLikeUserCount setTitleColor:[UIColor colorWithRed:50/255.0 green:79/255.0 blue:133/255.0 alpha:1.0] forState:UIControlStateNormal];
        [btnLikeUserCount addTarget:self action:@selector(btnLikeUserCountClick:) forControlEvents:UIControlEventTouchUpInside];
        [cell.viewLikeComment addSubview:btnLikeUserCount];
        posy = posy + 22;
    }
    else {
        cell.imgLikeSymbol.hidden = NO;

        NSMutableArray *arrLikeUserDetail = shareObj.vdLikeUserDetail;
        for (int i = 0; i<[arrLikeUserDetail count]; i++) {
            UserShare *shareObjU = [arrLikeUserDetail objectAtIndex:i];
            NSString *text;
            if (i == [arrLikeUserDetail count]-1) {
                text = shareObjU.userName;
            }
            else {
                text = [NSString stringWithFormat:@"%@,",shareObjU.userName];
            }
            CGSize constraint = CGSizeMake(280, 2000);
            CGSize size = [text sizeWithFont:[UIFont boldSystemFontOfSize:13] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];
            UIButton *btnLikeUserName = [UIButton buttonWithType:UIButtonTypeCustom];
            [btnLikeUserName.titleLabel setFont:[UIFont boldSystemFontOfSize:13]];

            if (posx + size.width > 280) {
                posy = posy + 22;
                posx = 18;
                btnLikeUserName.frame = CGRectMake(posx,posy,size.width,size.height);
                posx = posx + size.width + 5;
            }
            else {
                btnLikeUserName.frame = CGRectMake(posx,posy,size.width,size.height);
                posx = posx + size.width + 5;
            }
            btnLikeUserName.tag = shareObjU.userId;
            [btnLikeUserName setTitle:text forState:UIControlStateNormal];
            [btnLikeUserName setTitleColor:[UIColor colorWithRed:50/255.0 green:79/255.0 blue:133/255.0 alpha:1.0] forState:UIControlStateNormal];
            [btnLikeUserName addTarget:self action:@selector(btnLikeUserNameClick:) forControlEvents:UIControlEventTouchUpInside];
            [cell.viewLikeComment addSubview:btnLikeUserName];
        }
        posy = posy + 22;
    }

    cell.imgCommentSymbol.frame = CGRectMake(0,posy,15,15);
    posx = 18;

    NSMutableArray *arrCommentDetail = shareObj.vdCommentDetail;
    if ([arrCommentDetail  count] == 0) {
        cell.imgCommentSymbol.hidden = YES;
    }
    else if ([arrCommentDetail  count] > 3) {
        cell.imgCommentSymbol.hidden = NO;
        for (int i = 0; i<3; i++) {
            CommentShare *shareObjC = [arrCommentDetail objectAtIndex:i];
            NSString *text = shareObjC.userName;
            CGSize constraint = CGSizeMake(280, 2000);
            CGSize size = [text sizeWithFont:[UIFont boldSystemFontOfSize:13] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];
            UIButton *btnCommentUserName = [UIButton buttonWithType:UIButtonTypeCustom];
            [btnCommentUserName.titleLabel setFont:[UIFont boldSystemFontOfSize:13]];
            btnCommentUserName.frame = CGRectMake(posx,posy,size.width,size.height);
            btnCommentUserName.tag = shareObjC.userId;
            [btnCommentUserName setTitle:text forState:UIControlStateNormal];
            [btnCommentUserName setTitleColor:[UIColor colorWithRed:50/255.0 green:79/255.0 blue:133/255.0 alpha:1.0] forState:UIControlStateNormal];
            [btnCommentUserName addTarget:self action:@selector(btnCommentUserNameClick:) forControlEvents:UIControlEventTouchUpInside];
            [cell.viewLikeComment addSubview:btnCommentUserName];

            posx = posx + size.width + 5;
            NSString *text1 = shareObjC.commentText;
            CGSize constraint1 = CGSizeMake(280 - (size.width + 5), 2000);
            CGSize size1 = [text1 sizeWithFont:[UIFont systemFontOfSize:12] constrainedToSize:constraint1 lineBreakMode:UILineBreakModeWordWrap];
            UILabel *lblComment = [[[UILabel alloc] initWithFrame:CGRectMake(posx,posy,size1.width,size1.height)] autorelease];
            lblComment.lineBreakMode = UILineBreakModeWordWrap;
            lblComment.numberOfLines = size1.height/15;
            [lblComment setFont:[UIFont systemFontOfSize:12]];
            lblComment.text = text1;
            [cell.viewLikeComment addSubview:lblComment];
            posx = 18;
            posy = posy + size1.height + 2;
        }
        UIButton *btnCommentViewAll = [UIButton buttonWithType:UIButtonTypeCustom];
        [btnCommentViewAll.titleLabel setFont:[UIFont boldSystemFontOfSize:13]];
        btnCommentViewAll.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        btnCommentViewAll.frame = CGRectMake(posx,posy,200,16);
        btnCommentViewAll.tag = shareObj.vdId;
        [btnCommentViewAll setTitle:[NSString stringWithFormat:@"View all %d Comments",arrCommentDetail.count] forState:UIControlStateNormal];
        [btnCommentViewAll setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
        [btnCommentViewAll addTarget:self action:@selector(btnCommentViewAllClick:) forControlEvents:UIControlEventTouchUpInside];
        [cell.viewLikeComment addSubview:btnCommentViewAll];
        posx = 18;
        posy = posy + 16 + 2;
    }
    else {
        cell.imgCommentSymbol.hidden = NO;
        for (int i = 0; i<[arrCommentDetail count]; i++) {
            CommentShare *shareObjC = [arrCommentDetail objectAtIndex:i];
            NSString *text = shareObjC.userName;
            CGSize constraint = CGSizeMake(280, 2000);
            CGSize size = [text sizeWithFont:[UIFont boldSystemFontOfSize:13] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];
            UIButton *btnCommentUserName = [UIButton buttonWithType:UIButtonTypeCustom];
            [btnCommentUserName.titleLabel setFont:[UIFont boldSystemFontOfSize:13]];
            btnCommentUserName.frame = CGRectMake(posx,posy,size.width,size.height);
            btnCommentUserName.tag = shareObjC.userId;
            [btnCommentUserName setTitle:text forState:UIControlStateNormal];
            [btnCommentUserName setTitleColor:[UIColor colorWithRed:50/255.0 green:79/255.0 blue:133/255.0 alpha:1.0] forState:UIControlStateNormal];
            [btnCommentUserName addTarget:self action:@selector(btnCommentUserNameClick:) forControlEvents:UIControlEventTouchUpInside];
            [cell.viewLikeComment addSubview:btnCommentUserName];

            posx = posx + size.width + 5;
            NSString *text1 = shareObjC.commentText;
            CGSize constraint1 = CGSizeMake(280 - (size.width + 5), 2000);
            CGSize size1 = [text1 sizeWithFont:[UIFont systemFontOfSize:12] constrainedToSize:constraint1 lineBreakMode:UILineBreakModeWordWrap];
            UILabel *lblComment = [[[UILabel alloc] initWithFrame:CGRectMake(posx,posy,size1.width,size1.height)] autorelease];
            lblComment.lineBreakMode = UILineBreakModeWordWrap;
            lblComment.numberOfLines = size1.height/15;
            [lblComment setFont:[UIFont systemFontOfSize:12]];
            lblComment.text = text1;
            [cell.viewLikeComment addSubview:lblComment];
            posx = 18;
            posy = posy + size1.height + 2;
        }
    }

    cell.viewLikeComment.frame = CGRectMake(10,340,300,posy);
    cell.btnLike.frame = CGRectMake(10,340+posy+5,80,20);
    cell.btnComment.frame = CGRectMake(100,340+posy+5,80,20);
    cell.btnOther.frame = CGRectMake(260,340+posy+5,50,20);
    return cell;
}
4

2 に答える 2

0

init メソッドの VideoListCustomCell 内にボタンを追加します。

于 2013-03-04T07:30:45.643 に答える
0

以下を使用して試すことができます: UIButton *obj = [UIButton alloc]init];

于 2013-03-04T10:35:57.107 に答える