开发者

proper way to add button to the tableview programmatically

开发者 https://www.devze.com 2023-02-15 14:16 出处:网络
i added a button to my tableview programmatically but it is visible only if i select the tableview cell.how can i make it appear regardless of the selection of the tableview and i want to make the sel

i added a button to my tableview programmatically but it is visible only if i select the tableview cell.how can i make it appear regardless of the selection of the tableview and i want to make the selection style of tableviewcell none.how to proceed. this is the code i used

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

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }
   ContactDetails *cont= [self.contactarray objectAtIndex:indexPath.row];
    MyAppDelegate *delegate = [[UIApplication sharedApplication] delegate];

     for(ContactDetails *mycontact in delegate.contactsArray )
     {
         if([mycontact.contactID isEqualToString:cont.contactID])
         {
             UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
             button.frame = CGRectMake(100, 0, 100, 40);
             [button setTitle:@"add contact" forState:UIControlStateNormal];
             button.backgroundColor = [UIColor blueColor];
             [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
             [button addTarget:self action:@selector(deconnect) forControlEvents:UIControlEventTouchUpInside];
             [cell.contentView addSubview:button];
             [cell.contentView bringSubviewToFront:button];                                  
         }
     }

    cell.开发者_如何学PythontextLabel.text=cont.name;
    return cell;
}


sorry the right way was to put [cell addSubview:button]; sorry for trble

0

精彩评论

暂无评论...
验证码 换一张
取 消