1

I am adding image in tableVIew cell but it does not show. I am using if condition to give the image to button but it does not show.

Here is the code for the button addding

    addButton = [UIButton buttonWithType:UIButtonTypeCustom];
    addButton.Frame=CGRectMake(590,2,42,42);

    [addButton addTarget:self action:@selector(tab1Action:) forControlEvents:UIControlEventTouchUpInside];
    addButton.tag=indexPath.row;


    NSString*test=theData.Status;

    if ([test isEqualToString:@"1"]) {

        test=@"Already Member of the group";



    }

    else {

        test=@"";



        NSLog(@"Else is also Working Fine");




        [addButton setImage:[UIImage imageNamed:@"addbutton.png"] forState:UIControlStateNormal];

    }
    addButton.clipsToBounds=YES;
    [[cell contentView] addSubview:addButton];       

    cell.textLabel.font=[UIFont fontWithName:@"Helvetica" size:16];
    cell.textLabel.text=[NSString stringWithFormat:@"%@: %@",theData.GroupTitle,test];

    return cell;
4

3 回答 3

0

You don't need to add to cell's contentview. So do like this..

   [cell addSubview:addButton]; 
于 2013-07-19T08:09:33.773 回答
0

your button frame CGRectMake(590,2,42,42) is the error

frame.origin.x is too big than screen size

it is only on size 320,480 in developing

640,960 is automatic

于 2013-07-19T09:02:12.723 回答
0

// Create a table for different section of app

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

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (!cell) {

    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    

    }

    /* IMPORTANT: As we are using a "Dynamic Type", when table view reload we must remove previous views from container. */

    if ([cell.contentView subviews]){ for (UIView *subview in [cell.contentView subviews]) { [subview removeFromSuperview]; } }

    // create a rectangle box for image view UIImageView *iconImage = [[UIImageView alloc] init]; iconImage.frame = CGRectMake(12,4,53.5,53.5);

    // Create a label for cells UILabel *cellName = [[UILabel alloc] initWithFrame:CGRectMake(75,18,200,20)]; cellName.font = [self fontForBodyTextStyle];

    NSString *cellNameStr = [NSString stringWithFormat:@"%@",self.tableCellNames[indexPath.row]];

    // Select path row tab actions switch (indexPath.row) { case 0:

        cellName.text = cellNameStr;
        iconImage.image = [UIImage imageNamed:@"condition.png"];
        [cell.contentView addSubview:iconImage];
        [cell.contentView addSubview:cellName];
    
        break;
    
    case 1:
       cellName.text = cellNameStr;
        iconImage.image = [UIImage imageNamed:@"videos.png"];
        [cell.contentView addSubview:iconImage];
        [cell.contentView addSubview:cellName];
        break;
    
    case 2:
        cellName.text = cellNameStr;
        iconImage.image = [UIImage imageNamed:@"provider.png"];
        [cell.contentView addSubview:iconImage];
        [cell.contentView addSubview:cellName];
        break;
    
    case 3:
        cellName.text = cellNameStr;
        iconImage.image = [UIImage imageNamed:@"info.png"];
        [cell.contentView addSubview:iconImage];
        [cell.contentView addSubview:cellName];
        break;
    
    default:
        NSAssert(NO, @"Unhandled value in cellForRowAtIndexPath");
        break;
    

    }

    return cell; } Thanks VKJ,

于 2013-10-25T09:49:41.297 回答