我可以用textlabel
和detaillabeltext
創建tableview
。如何將UIButton放入uitableview單元格中?
除此之外,是否可以將UIButton
添加到單元格中。
的detaillabeltext後,我的意思是,我可以把一個UIButton
(如「刪除」按鈕)
目前,我有以下代碼
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
//-----------------------------------------------------------------------------------------------------
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
profileName = [appDelegate.sentItemsList objectAtIndex:indexPath.row];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
NSString *subjectData = [profileName.sent_subject stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]];
cell.textLabel.text = [NSString stringWithFormat: @"%@ ", subjectData];
cell.textLabel.font = [UIFont boldSystemFontOfSize:13];
NSString *CompanyName = [profileName.sent_content stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]];
cell.detailTextLabel.text = [NSString stringWithFormat: @"%@ ",CompanyName];
cell.detailTextLabel.font = [UIFont systemFontOfSize:10];
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
cell.backgroundColor = [UIColor colorWithRed:230.0/255.0 green:249.0/255.0 blue:230.0/255.0 alpha:2.0];
return cell;
}
感謝您的時間和幫助!
可能重複[UIButton的在UITableView的細胞像「刪除事件」(http://stackoverflow.com/questions/1076785/uibutton-in-uitableview- cell-like-delete-event) – 2011-05-26 04:20:12
對於什麼,你想添加按鈕?就像如果你想實現刪除功能一樣,你可以使用附件,否則你將不得不實現所有東西作爲你的表視圖單元格的子視圖。 – rptwsthi 2011-05-26 04:26:55
@rptwsthi:不喜歡刪除功能。我想打電話給我的「添加到收藏夾」按鈕 – user198725878 2011-05-26 04:52:15