How to make different value in uitableview cell?

Hi all. I have a table when clicking on a cell, move to the next table. But when I set the value for cells in the second table, all cells have the same text. For example if I clicked on the first cell of the first table should open a table with values: 1, 2, 3; if I click on the second cell of the first table should open a table with values: 4, 5, 6, etc. thank you All.
April 4th 20 at 00:30
1 answer
April 4th 20 at 00:32
Solution
Most likely you need to handle the method didSelectRowAt of the Protocol UITableViewDelegate.

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
 switch indexPath.row {
 case 0:
 // Do something by pressing on the cell with index 0
break
 case 1:
 // Do something by pressing on the cell with the index 1
break
default:
break
}
}


More you can look in my video about the table.
The name of the cell in the first table: "One", Two", "Three". And when we go to the first cell of the "One" is the name of cells should be 1,2,3. And when we go into "Two" the name of the cell should be 4,5,6. That is simply needs to have a different name. But if I set cell.textLabel.text = @[@"1", @"2", @"3"], the name passed on to all 9 cells, and it should, only the first 3. Thank you. - lambert_Wunsch32 commented on April 4th 20 at 00:35
@lambert_Wunsch32, show 3 methods of configuration cells - leonardo commented on April 4th 20 at 00:38
This is my first table(main):
- (void)viewDidLoad {
devices = @[@"iPhone", @"iPad", @"iMac"];
[super viewDidLoad];


// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;

// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
#warning Incomplete implementation, return the number of sections
return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
#warning Incomplete implementation, return the number of rows
return 3;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];

// Configure the cell...
cell.textLabel.text = devices[indexPath.row];
return cell;
}


This is the second:
- (void)viewDidLoad {
arra = @[@"cell2", @"cell3", @"cell4"];
model1 = @[@"iphone 7", @"iphone se", @"iphone xr"];
model2 = @[@"ipad air", @"ipad air2", @"ipad pro"];
model3 = @[@"imac 2018", @"imac 2019", @"new imac"];
[super viewDidLoad];

// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;

// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
#warning Incomplete implementation, return the number of sections
return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
#warning Incomplete implementation, return the number of rows
return 3;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell2" forIndexPath:indexPath];
/*
switch (indexPath.row) {
case 0:
cell.textLabel.text = @"A";
break;
case 1:
cell.textLabel.text = @"B";
case 2:
cell.textLabel.text = @"C";
default:
break;
}
*/
// Configure the cell...
return cell;
} - lambert_Wunsch32 commented on April 4th 20 at 00:41
@lambert_Wunsch32, attach a file and all the code with the controller names and methods of these controllers. - leonardo commented on April 4th 20 at 00:44
I can't attach the file for some reason. He does not write "failed to load file". - lambert_Wunsch32 commented on April 4th 20 at 00:47
@lambert_Wunsch32, upload to the cloud, link here. - leonardo commented on April 4th 20 at 00:50
https://drive.google.com/file/d/1IZeOsS0IscpKhhjF9... - lambert_Wunsch32 commented on April 4th 20 at 00:53
@lambert_Wunsch32, you have now by clicking on the cell does not occur any transition. Methods of treatment of depression no.
Cells in the root controller there are: ["iPhone", @"iPad", @"iMac"], they had to seem. - leonardo commented on April 4th 20 at 00:56
I before doing this deleted the relationship between the tables. - lambert_Wunsch32 commented on April 4th 20 at 00:59
@lambert_Wunsch32, show your relationship between the tables. The code I can see should work properly if correctly configured transitions. - leonardo commented on April 4th 20 at 01:02
The transition works, but the name of cells is the same everywhere. One minute. I will make the spacecraft was originally. - lambert_Wunsch32 commented on April 4th 20 at 01:05
https://drive.google.com/file/d/1Ry9HU5w_mufzukmaG... - lambert_Wunsch32 commented on April 4th 20 at 01:08
@lambert_Wunsch32, you in the method configure the cell in only one array model1.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell2" forIndexPath:indexPath];
 cell.textLabel.text = model1[indexPath.row];
 // Configure the cell...
 return cell;
}


Referral to other arrays no. Where they are invoked? - leonardo commented on April 4th 20 at 01:11
@leonardo, If I pass the 3 arrays, with each array takes one value and is transmitted first value from each array. But all the array values are not transmitted. - lambert_Wunsch32 commented on April 4th 20 at 01:14
@lambert_Wunsch32, you just have three arrays. You can delete the rest, they are not used anywhere.
The values just from model1, I copied the above from your project configuration method of a cell. No references to other arrays. - leonardo commented on April 4th 20 at 01:17
How to do cell iPhone was an array of model1, model2 iPad, iMac model3? - lambert_Wunsch32 commented on April 4th 20 at 01:20
@lambert_Wunsch32, you are probably a beginner.

You need to use my answer above. Depending on the tap on the cell to show the controller. Will have to write code. Before his show, set it to the data - in your case the array.

If the answer seems unclear, go back to the study table of delegates and controllers. - leonardo commented on April 4th 20 at 01:23
Yes, only teach. Thanks for the reply. - lambert_Wunsch32 commented on April 4th 20 at 01:26
Will deal with the delegates of the table and the supervisors. - lambert_Wunsch32 commented on April 4th 20 at 01:29
And it's hard to do? - lambert_Wunsch32 commented on April 4th 20 at 01:32
@lambert_Wunsch32, no. The basics, you might say. In practice, will encounter every day) take a Look at my video, now it may seem complicated, but something about table learn. - leonardo commented on April 4th 20 at 01:35
That which you took off earlier? - lambert_Wunsch32 commented on April 4th 20 at 01:38
@lambert_Wunsch32, Yes, the link in the answer. - leonardo commented on April 4th 20 at 01:41
I have one more question. I did the app recipe book and used in this search bar, but when I switched to the search result through the search bar, then it's a "mess." Can you tell what the problem is and how to fix it. Thank you. - lambert_Wunsch32 commented on April 4th 20 at 01:44
@lambert_Wunsch32, you need to watch. So do not say) - leonardo commented on April 4th 20 at 01:47
If not hard: https://drive.google.com/file/d/1eUZupycp68oX3ZDP3... - lambert_Wunsch32 commented on April 4th 20 at 01:50

Find more questions by tags iOSSwift