单击iphone上的单元格按钮

时间:2011-01-24 03:38:18

标签: objective-c ios uitableview ios-simulator

我在所有单元格中都创建了一个按钮,但是根据按钮单击,我无法区分您使用的单元格

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


callsms = [[NSMutableArray alloc] init];

            NSString *st=aCat.names;

            NSLog(@" AND THE STRING IS %@",st);
            **[callsms addObject:st];// holds all the values**


        myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];//
        myButton.frame = CGRectMake(220, 20, 50, 30); // position in the parent view and set the size of the button
        [myButton setTitle:@"call!" forState:UIControlStateNormal];
        // add targets and actions

        [myButton addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
        // add to a view
        //[self addSubview:myButton];
        //myButton.tag=jk;//indexPath.row;
        //[self.view addSubview:myButton];

            myButton.tag=indexPath.row;
            [cell.contentView addSubview:myButton];

}

但我无法添加按钮标记

- (void)buttonClicked:(id)sender{
//  NSLog(@" BUTTON SI CLOEKCD");
    //  NSLog(@" call sms  %@",callsms   );






    if(myButton.tag==1)
    {

        NSLog(@" BUTTON 2 CLOEKCD");//not working


    }
    if(myButton.tag==5)
    {

        NSLog(@" BUTTON 3 CLOEKCD");not working


    }
    if(myButton.tag==6)
    {
        //[self readAnimalsFromDatabase];

        NSLog(@" BUTTON 6 CLOEKCD%@",callsms);not working




    }

}

///更新//////////////////////

而不是标签我正在使用这个,现在这是好方法吗?

- (void)buttonClicked:(id)sender{
//  NSLog(@" BUTTON SI CLOEKCD");
    //  NSLog(@" call sms  %@",callsms   );



    NSIndexPath *indexPath =[self.tabelView  indexPathForCell:(UITableViewCell *)[[sender superview] superview]];


    NSUInteger row = indexPath.row;


    NSLog(@" BUTTON 2 CLOEKCD%d",row);
}

///但是通过这种方式,我必须为所有值写 if(row == 1)到10以及每个代码,不是有任何简单的方法

0 个答案:

没有答案