Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialerick spinoza
3,820 PointsConnecting UIViewController with UITableView
Hello, can you help me find a problem ... I want to connect 2 views programmatically the first UIViewController has buttons made with code and want each button to communicate with a tableview specifically because there are 9 tableviews but I want to reuse code and not be doing 9 tableviews in the storyboard, i want to explain better that pressing the button 1 is in the tableview and display information relevant only to that button and so on for each button, using a tableview only made in the storyboard can help me please ... thanks .
2 Answers
Vladimir Cezar
7,710 PointsLet us say you have two arrays, array1 and array 2 and depending on the button you press you want to show the items of one or the other on the same UITableView. All you have to do is assign the array property of your delegate to the array and reload the data. For example, let usa say that your UIViewController has a property
@property (nonatomic, strong) NSArray *arrayWithMyItems;
and you have two array variables, array1 and array2 with different sets of data.
All you have to do is:
self. arrayWithMyItems = array1;
[self.tableView reloadData];
or
self. arrayWithMyItems = array2;
[self.tableView reloadData];
erick spinoza
3,820 PointsHi, thank you for responded, but the first problem is how connect this array with a button, in otherwise, i have one first view controller and i hope that push the button 1 reveal the information in array 1, how connect first viewcontroller whit second tableview that content the arrray 1, thank you