Bir tabloyu görüntülemek istediğim bir uygulama üzerinde çalışıyorum. Kullanıcılarla doldurulmuş bir tablo görünümü ve satır seçildiğinde bir konuşma içeren yeni bir görünüm görüntülenir (temelde bir mesajlaşma uygulaması). Şimdilik sadece FirstViewController'ımda bir satıra dokunduğumda, bir etiket üzerinde seçilen kullanıcının adı ile SecondViewController'ın görüntülenmesini istiyorum. Ama bunu işe alamıyorum çünkü bir satıra her dokunduğumda indexPath 0, si her zaman görüntülenen ilk kullanıcı adıdır.Tablodaki segue ile veri aktarmaViewView
#import "GSBChatViewController.h"
#import "GSBConversationViewController.h"
@interface GSBChatViewController()
@property (weak, nonatomic) IBOutlet UITableView *userTableView;
@end
@implementation GSBChatViewController
@synthesize chatUsers;
- (void)viewDidLoad {
[super viewDidLoad];
GSBChatUsers *user1 = [[GSBChatUsers alloc]initWithName:@" John DOE" andPicture:@"photo.jpg" andLastMessage:@"Ca marche!"];
GSBChatUsers *user2 = [[GSBChatUsers alloc]initWithName:@"Justine DUBOIS" andPicture:@"photo.jpg" andLastMessage:@"Salut, ça va?"];
GSBChatUsers *user3 = [[GSBChatUsers alloc]initWithName:@"Jacques LAPORTE" andPicture:@"photo.jpg" andLastMessage:@"Réunion le 23 à 15h, c'est bon pour toi?"];
GSBChatUsers *user4 = [[GSBChatUsers alloc]initWithName:@"Guillaume DUPOND" andPicture:@"photo.jpg" andLastMessage:@"OK, parfait"];
GSBChatUsers *user5 = [[GSBChatUsers alloc]initWithName:@"Françoise MARTIN" andPicture:@"photo.jpg" andLastMessage:@"Tu as posé tes congés?"];
GSBChatUsers *user6 = [[GSBChatUsers alloc]initWithName:@"Jean-Jacques CELESTIN" andPicture:@"photo.jpg" andLastMessage:@"Je prends note"];
chatUsers = [[NSArray alloc]initWithObjects:user1,user2,user3,user4,user5,user6, nil];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
NSIndexPath *indexPath = [self.userTableView indexPathForCell:sender];
NSLog(@"Path: %@",indexPath);
GSBConversationViewController *destVC = [segue destinationViewController];
GSBChatUsers *selectedUser =[chatUsers objectAtIndex:indexPath.row];
NSLog(@"%ld",[self.userTableView indexPathForCell:sender].row);
NSString *userName = selectedUser.name;
NSLog(userName);
destVC.Test=userName;
}
#pragma mark - Datasource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Retourne le nombre d'éléments de notre liste
NSLog(@"Number of rows: %ld",chatUsers.count);
return [chatUsers count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
// Instancie notre cellule par son identifier
GSBTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"userCell"];
// On récupère l'item que l'on va traiter
GSBChatUsers *user = [chatUsers objectAtIndex:indexPath.row];
// On affecte les valeurs de notre user aux éléments de notre cellule
[cell.userName setText:user.name];
[cell.profilePicture setImage:[UIImage imageNamed:user.picture]];
[cell.lastMessage setText:user.lastMessage];
NSLog(@"%@",chatUsers);
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
NSLog(@"%@",_cellTitle);
//[self performSegueWithIdentifier:@"conversationSegue" sender:[chatUsers objectAtIndex:indexPath.row]];
}
@end
Ben this answer yanı sıra this one baktı ama bunların hiçbiri işe: İşte benim kod parçasıdır. (Önceleri yardımcı oldular çünkü önceden etiketin metnini bile değiştiremedim).
Yasal Uyarı: Bu bir okul projesi içindir ve yüzde yüz oranında Internet'ten yardım isteyebilirim. ingilizce benim ana dili değil belki bazı noktalarda açık değilim, daha fazla bilgiye ihtiyacınız varsa lütfen bana bildirin.
Yardımlarınız için teşekkürler!
:
Uygulamanız şuna benzer olabilir? –
@ AndréSlotta Evet, ilkViewController'ın prototip hücresinden ikinciViewController – nommis
no'lu kuyucuktan, bu durumda "didSelectRowMethod" öğesine değil, yalnızca "prepareForSegue" öğesine ihtiyacınız yoktur. ve "HazırlıkForSegue" de her zaman şu anda satır ** 0 ** yazdırır? –