我想向表格單元格添加一個按鈕。 「刪除事件」中的日曆應用程序激發了我...(一個類似的例子是「共享聯繫人」中的聯繫人)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