2011-10-20 52 views
1

我都想只知道....添加按钮在表行每个单元.....程序运行时 ,也希望点击时识别按钮....添加按钮

我不写code..here ....

//---insert individual row into the table view--- 


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

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:[NSString stringWithFormat:@"Cell %i",indexPath.section]]; 

    if (cell == nil) { 

     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:[NSString stringWithFormat:@"Cell %i",indexPath.section]] autorelease]; 

    } 


    NSLog(@"i am here in table function..........now"); 


    //cell.textLabel.text = [data objectAtIndex: indexPath.row]; 

    search_items *pro = [searchCount objectAtIndex:[indexPath row]]; 

    cell.textLabel.text = pro.s_showroomName; 



    UIButton* aButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 

     [aButton setTag:[indexPath row]]; 

     [aButton addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside]; 


    [cell.contentView addSubview:aButton]; 

     return cell; 
} 

-(void)buttonClicked:(UIButton*)sender { 
    int tag = sender.tag; 

///and rest code here..... 

} 

此代码不能正常工作.... :) 请给我解:)

在此先感谢.....请给我任何教程也..

+0

可能重复http://stackoverflow.com/questions/1802707/detecting-which -uibutton-was-press-in-a-uitableview) – Vladimir

+1

哪个'代码无法正常工作'。你能看到表格视图单元格上的按钮吗?如果不是,请尝试将按钮帧设置为x = 0,y = 0,w = 100,h = 30。你还可以看到填充的表格(包含文本的表格单元格)吗? – Sahil

+0

@sahil ....我看到填充表格与文本..我从数据库使用NSMuttable数组searchCount ...(你是右边框x = 0,y = 0,w = 100,h = 30)...感谢兄弟 – GauravBoss

回答

1

设置帧为您的按钮这样的..

aButton.frame = CGRectMake(0, 0,150,44); 
的[检测其中的UIButton在一个UITableView压](
+0

thanks..again ... Trisha ...只有一行,我的代码工作正常...... :) – GauravBoss