开发者

How to identify each button in table row?

I want buttons in table row 开发者_运维百科to show different titles depending on database values.

But I am facing issue in uniquely identifying each buttons i.e button 0, button 1 etc.

Note, button is in table row.


Have a look at this thread how-to-select-particular-check-box-in-tableview-which-is-inserted-in-table-cell


To uniquely identify the buttons in TAbleView you need to set the tag of each & every button like

This this out,this will definitely solve your problem :)

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

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
    }

        UIButton *CameraBreak=[[UIButton alloc]init];
        CameraBreak.frame=CGRectMake(28, 33, 60, 40);
        CameraBreak.tag=indexPath.row;
        [CameraBreak setImage:[UIImage imageNamed:@"Camera.png"] forState:UIControlStateNormal];

        [CameraBreak addTarget:self action:@selector(CameraBtn_Clicked:) forControlEvents:UIControlEventTouchUpInside]; 
        [cell.contentView addSubview:CameraBreak];
            //[CameraBreak release]; 
    return cell;
    }


-(IBAction)CameraBtn_Clicked:(id)sender
{
    NSLog(@"%d",[sender tag]); /This will print the tag of button which you have pressed in TableView
}

Either for Dynamic Records use the Following link :

How to Select particular check Box in tableView which is inserted in table cell interface builder in iphone

Now that will work


use the NSObject property "tag" ... e.g.

 UIButton* myButton;
 myButton.tag = EON; OR myButton.tag = EOFF ;

if(myButton.tag == EON)
{
   myButton.tag = EOFF; 
  //Do As per your requirement 
}
else if(myButton.tag == EOFF)
{
  myButton.tag = EON; 
  //Do As per your requirement 
}


You can use table indexpath.row + your own values (0,1,2...) as tag to each button. I m not sure but atleast you can try.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜