我有一個UITableViewCell
(自定義單元格),其中我創建了一些按鈕和文本字段並將標籤分配給按鈕和文本字段。但是我點擊按鈕時無法獲得按鈕標題和文本框值。如何獲得單擊按鈕上的UITableviewcell(自定義單元格)值
在cellForRowAtIndexPath
`[((CustomCell *) cell).btn setTag:rowTag];
[((CustomCell *) cell).textField2 setTag:rowTag+1];`
-(IBAction)submitBtnAction:(UIControl *)sender
{
for (int i=0; i<[self->_dataArray count]; i++)
{
NSIndexPath *myIP = [NSIndexPath indexPathForRow:i inSection:0];
NSLog(@"myIP.row %d",myIP.row);
UITableViewCell *cell = [tblView1 cellForRowAtIndexPath:myIP];
NSLog(@"tag %d",cell.tag);
UIButton *btn = (UIButton *)[cell.contentView viewWithTag:i];
NSLog(@"btn text %@, tag %d",btn.titleLabel.text,btn.tag);
UITextField *tf = (UITextField *)[cell.contentView viewWithTag:i+1];
NSLog(@"tf text %@, tag %d",tf.text,btn.tag);
}
}
我收到提示這樣
-[UITableViewCellContentView titleLabel]: unrecognized selector sent to instance 0x71844e0
2013-07-17 13:48:29.998 Text[1271:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITableViewCellContentView titleLabel]: unrecognized selector sent to instance 0x71844e0'
感謝您的答覆......其工作很好 – user1831389
@Amar ....可以使用此內容視圖的標籤獲取文本字段和按鈕的值.... [((CustomCell *)cell).contentView setTag:rowTag]; – user1831389
@ user1831389我認爲在這種情況下,您應該使用'[cell viewWithTag:tag]'而不是'cell.contentView'來訪問button,textfield。 – Amar