How can I pass textField data from a UIView Controller text field to a tableview label in a cell? I would like to somehow add the textfield data to an Array so that I can set the number of rows return value to the arrays count.
I’ve added an NSMutable array to my model.
In my view controller I’m implementing the prepareForSegue method
if ([segue.identifier isEqualToString:@"Details"]){
MileageDetailViewController * mdv = [segue destinationViewController];
NSString *text;
startTextField.text = text;
mdv.label.text = text;
I’ve tried this several different ways. I’ve done this with an array and tried to add text object an array but that didn’t display either. This last way I tried using a label and adding the text from textField to a tableview Label.
In the tableView I add this code to grab the text from the viewController.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Reuse"];
UILabel *labe = (UILabel *) [cell viewWithTag:20];
labe.text = label.text;
// Configure the cell...
return cell;
The Code examples below are just to get you started. But I strongly, strongly recommend you follow the tutorials on Ray Wenderlich’s site (link) as you seem to just be starting on iOS development.
Passing data between view controllers using
prepareForSegue:(with comments in code block):Now onto the methods in your controller with the table view:
Hope this helps; iOS development is a lot of fun but following some tutorials will really help you get up-to-speed.