[英]how to add textfield in tableview cell(each row) and set tag to each textfield to access it's text
如何在tableview單元格中添加textfield(在每一行上)。 此文本字段將位於每行的中間。 並在單元格的每個文本字段上設置Tag以訪問其文本。
當然可以,一個小例子:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"test"];
if(cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"test"] autorelease];
UITextView *tv = [[UITextView alloc] initWithFrame:CGRectMake(0, (cell.contentView.bounds.size.height-30)/2, cell.contentView.bounds.size.width, 30)];
[cell.contentView addSubview:tv];
[tv setDelegate:self];
tv.tag = indexPath.row;
}
return cell;
}
...
- (void)textViewDidEndEditing:(UITextView *)textView {
NSLog(@"%d", textView.tag);
[textView resignFirstResponder];
}
...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.