我想知道....在表格行的每个单元格中添加按钮.....在运行时以编程方式 并且还希望在点击时识别按钮....
我写了一些小代码..那......
//---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 :(得分:1)
像这样设置按钮的框架..
aButton.frame = CGRectMake(0, 0,150,44);
答案 1 :(得分:0)
检查问题,你可能会得到一些帮助运行时添加按钮和调用它们的方法。 iPhone: Add UIButton's horizontally with scrollbar provision in a View or TableView?