在我的應用程序中有一個UITableView。在表格單元格中放置兩個標籤和一個按鈕。按鈕高度等於(label1 + label2)高度。這些是顯示內容。和按鈕是爲了行動。在這裏我的問題是我無法在所有部分執行按鈕操作。點擊時只有一部分工作。UITableView單元中的按鈕動作
下面是代碼我用來放置標籤和按鈕
artistButton = [[UIButton alloc] initWithFrame:CGRectMake(11.0, 6.0, 170.0, 50.0)];
artistButton.backgroundColor = [UIColor redColor];
[self.contentView bringSubviewToFront:artistButton];
[self.contentView addSubview:artistButton];
artistLabel1 = [[UILabel alloc] initWithFrame:CGRectMake(11.0, 6.0, 170.0, 27.0)];
artistLabel1.textAlignment = UITextAlignmentLeft;
artistLabel1.textColor = [UIColor colorWithRed:0.14 green:0.29 blue:0.42 alpha:1];
artistLabel1.font = [UIFont boldSystemFontOfSize:15.0];
artistLabel1.backgroundColor = [UIColor blueColor];
[self.contentView addSubview:artistLabel1];
artistLabel2 = [[UILabel alloc] initWithFrame:CGRectMake(11.0,20.0, 170.0, 27.0)];
artistLabel2.textAlignment = UITextAlignmentLeft;
artistLabel2.textColor = [UIColor grayColor];
artistLabel2.font = [UIFont boldSystemFontOfSize:12.0];
artistLabel2.backgroundColor = [UIColor grayColor];
[self.contentView addSubview:artistLabel2];
任何一個可以幫助或建議。 在此先感謝。
u能PLZ澄清這行:「按鈕動作中的所有部分」 – sandy 2012-04-27 09:54:22
你需要一個按鈕(它比觸發接觸電池本身另一動作)。你應該使用tableView委託('tableView:didSelectRowAtIndex:')。如果你需要一個按鈕,你應該使用'[UIButton buttonWithType:type]'來創建它。 – calimarkus 2012-04-27 10:37:15
看起來像標籤覆蓋了按鈕框。嘗試將這兩個標籤的內容設置爲按鈕標題。 ' - (void)setTitle:(NSString *)title forState:(UIControlState)狀態; '。您可以調整此「titleLabel」的屬性以使內容出現在多行中。 – 2012-04-27 10:43:31