我想向表格单元格添加一个按钮。 “删除事件”中的日历应用程序激发了我...(一个类似的例子是“共享联系人”中的联系人)UITableView单元格中的UIButton类似于“删除事件”
截至目前有
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//..yadayadayada
cell = [tableView dequeueReusableCellWithIdentifier:@"buttonCell"];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"buttonCell"] autorelease];
}
UIButton *button = [UIButton buttonWithType:UIButtonTypeInfoDark];
[button setBackgroundColor:[UIColor redColor]];
button.titleLabel.text = @"Foo Bar";
[cell.contentView addSubview:button];
其产生的按钮,确实如此。它看起来并不怎么样(很明显,我从来没有在iPhone中处理过按钮),但是这至少是正确的方法吗?
按钮的合成动作取决于它所在的行是否会有所不同? (例如,通过电子邮件发送当前联系人在这一行,等等......) – 2009-07-02 21:51:00
如果是这样,你可以设置每个单元格按钮的标签,indexPath行,然后在选择器中读取发件人的标签,触摸。 – mmc 2009-07-02 21:54:46
那么,就像“删除事件”一样,我只在UI的底部有一个按钮,即最后一行。 – 2009-07-02 21:59:24