Monday, 20 October 2014

How to add a button to specific row in tableview

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"CellIdentifier";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
//UITableViewCell *cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil] autorelease];

    UIButton *button = nil;
    
   // cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];

    if (cell == nil)
    {
       //  cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
        
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
        
        button = [[UIButton alloc] initWithFrame:CGRectZero];
        button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        button.tag = 579;
       [button setTitle:@"Show View" forState:UIControlStateNormal];
       [cell.contentView addSubview:button];
    }
    
    if (displayObject11.count != 0) {            
        
            if (indexPath.row == 2) {
                button = (UIButton*)[cell viewWithTag:579];
                button.frame = CGRectMake(180.0, 10, 160.0, 40.0);
              }              
    }    
    return cell;

}

No comments:

Post a Comment