Deux contrôleurs UITableView dans SplitViewController en iPad, délégué
Salut Ceci est ma première application iPad et d'essayer de transférer mon application iPhone pour iPad. J'ai suivi tous les tutoriels de http://www.raywenderlich.com/ ayant encore un problème.
examen a également cette question et ayant encore le problème. Fondamentalement, j'ai deux UITableViewControllers dans SplitViewController et quand je clique sur la cellule de vue de table dans le contrôleur de vue racine, je veux remplir les détails dans DetailsViewController dans le côté droit sur une autre vue de table.
Le problème est que je peux gérer pour transmettre les données du tableau de mais je ne peux pas appeler tableview méthode de rechargement.
Voici le code
LeftViewController
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSUInteger row = [indexPath row];
if (row == 0){
NSLog(@"Row 0 Pressed");
RightViewController *rightvc = [self.storyboard instantiateViewControllerWithIdentifier:@"displayenglish"];
_locallayleft = [ConversationDatabase database].conversationsInfos;
NSLog(@"Just pushed the array");
rightvc.detailItem = _locallayleft;
rightvc.title = @"Greetings";
}
else if (row == 1) {
NSLog(@"Row 1 Pressed");
RightViewController *rightvc = [self.storyboard instantiateViewControllerWithIdentifier:@"displayenglish"];
_locallayleft = [ConversationDatabase database].conversationsInfosgeneral;
rightvc.detailItem = _locallayleft;
rightvc.title = @"General Conversation";
}
-----------------------------------------------------------------------------------------
RightViewController
- (void)setDetailItem:(NSArray *)newDetailItem
{
if(_detailItem != newDetailItem) {
_detailItem = newDetailItem;
[self configureView];
}
}
- (void)configureView
{
if (self.detailItem) {
self.locallay = self.detailItem;
_listOfCoversation = [[NSMutableArray alloc] init];
for (ConversationInEnglish *c in _locallay)
{
NSString *english = c.english;
NSLog(@"setDetails Item get called");
NSLog(@"%@",english);
[_listOfCoversation addObject:english];
}
[self.tableView reloadData];
NSLog(@"Trying to reload TableView");
}
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self configureView];
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [_locallay count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"English";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
ConversationInEnglish *con = _locallay [indexPath.row];
_englishLabel = (UILabel *) [cell viewWithTag:200];
_englishLabel.text = con.english;
NSLog(@"My data from cell %@",con.english);
[_englishLabel setFont:[UIFont fontWithName:@"Open Sans" size:22]];
_myanmarLabel = (UILabel *) [cell viewWithTag:300];
[_myanmarLabel setFont:[UIFont fontWithName:@"TharLon" size:17]];
_tonebasedLabel = (UILabel *) [cell viewWithTag:400];
_tonebasedLabel.text = con.tone_based;
UIColor *background = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"tableviewcell.png"]];
self.tableView.backgroundColor = background;
return cell;
}
Vous n'avez pas besoin d'obtenir un pointeur sur votre contrôleur de vue partagé de cette façon depuis le contrôleur maître est intégré dans le contrôleur de vue partagé. Utilisez simplement self.splitViewController. – rdelmar
Bon point - mis à jour le code pour refléter cela. Merci. – stevex
Salut les gars. Merci beaucoup. La réponse est sur place. Ça marche. Yahoo! –