Reputation:
I have multiple sections in my UITableView
(about 12 sections) and each section has one or more rows. How can I get a section number in my UITextField
Delegate method, when I select a row ?
Upvotes: 0
Views: 2412
Reputation: 16543
If you added the textfield in the cell like
[cell.contentview addSubview:yourtextfield];
Then On the Textfield Delegate
UITableViewCell *cell = (UITableViewCell *)[[textField superview] superview];
NSIndexPath *indexPath = [yourTableView indexPathForCell:cell];
NSLog(@"your Indexpath %d",indexPath.section);
Upvotes: 3
Reputation: 4249
UITableViewCell *cell = (UITableViewCell *)[[textField superview]superview];
NSIndexPath *indexPath = [yourTableView indexPathForCell:cell];
NSLog(@"your Indexpath %d",indexPath.section);
however i suggest u in future create a customcell when performing tag operations with uitableviewcell
Upvotes: 0
Reputation: 4901
it display tag value,text field value,try this code(use tag)
- (void)textFieldDidEndEditing:(UITextField *)textField {
NSLog(@"%d : %@", textField.tag,textField.text);
[textField resignFirstResponder];
}
Upvotes: 0
Reputation: 8053
Try This:-
-(void) textFieldDidBeginEditing:(UITextField *)textField {
UITableViewCell *clickedCell = (UITableViewCell *)[textField superview];
int section = [topicTable indexPathForCell:clickedCell].section;
NSLog(@"section %d", section);
}
Upvotes: 1
Reputation: 3802
When the user selects the row, your code needs to handle the call to
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
** your code here**
}
the indexPath
passed into this method contains both the section and the row. The best way to find out how to use it is to look at the documentation for NSIndexPath, but I believe that something like
indexPath.section
is what you need.
Upvotes: 1
Reputation: 1289
If you have manually created the table view in interface builder, i.e. with static cells then you could use tags in each UITextField and then check that in the delegate method.
For 12 sections you could number the tags as , e.g. 1203 is row 3 in section 12 or 600 is row 0 in section 6.
Upvotes: -1