I recommend you use a datasource similar to this:
NSMutableArray *tableViewData = [NSMutableArray array];
[tableViewData addObject:@[ @{@"textfield" : YourTextField} ]];
[tableViewData addObject:@[ @{@"textfield" : YourTextField} ]];
[tableViewData addObject:@[ @{@"textfield" : YourTextField} ]];
[tableViewData addObject:@[ @{@"textfield" : YourTextField} ]];
The above code represents tableViewData
, containing 4 arrays, each array contains one dictionary which will maintain the data for a single cell. In my example I have just used a single key-value pair of a UITextField
.
You can dynamically create this however you like, and your delegate and datasource methods can read from it. Rather than having 3 separate arrays.
E.g.
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return [tableViewData count];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [[tableViewData objectAtIndex:section] count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSDictionary *cellData = [[tableViewData objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
// Create your cell and use the data stored in the dictionary
}
By using the above approach, you are able to update this dictionary, and maintain a state for all of your UITableView
in a single place, and it keeps the code tidy and readable. To access any UITextField
, just find it in the dictionary in the UITableView
datasource and delegate methods.
Hope this helps!