【发布时间】:2009-07-02 21:32:01
【问题描述】:
我想在表格单元格中添加一个按钮。日历应用中的“删除事件”启发了我……(类似情况是联系人中的“共享联系人”)
目前有
- (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 中的按钮),但这至少是正确的方法吗?
【问题讨论】:
-
按钮的最终操作会根据它所在的行而有所不同吗? (例如,通过电子邮件发送此行中的当前联系人等...)
-
如果是,您可以将每个单元格按钮的标签设置为 indexPath 行,然后在触摸执行的选择器中读取发送者的标签。
-
好吧,就像“删除事件”一样,我在 UI 底部(即最后一行)只有一个按钮。
标签: iphone uitableview uibutton