設定:
MainViewController
オブジェクトの を保持しNSMutableArray
ます。オブジェクトは、 aとivarNewContact
を持つmy のインスタンスです。をタップすると、すべてのオブジェクト ivar (および) がテーブルに表示されます。firstName
contactImage
showAllContactsBtn
MainViewController
AllContactsViewController
firstNames
contactImages
AllContactsViewController
問題は、データを適切に渡さないが、修正方法がわからないことだと思います。言及する価値があるのは、 NSLog
ステートメントが表示されcellForRowAtIndex
ないため、メソッドがまったく呼び出されない可能性があることです。
MainViewController.m
- (IBAction)showAllCBtnTapped:(id)sender
{
AllContactsViewController *nAllCVC = [[AllContactsViewController alloc]init];
nAllCVC.allContactsArray = self.contactsArray; // Properly passed the data???
nAllCVC.delegate = self;
nAllCVC.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:nAllCVC animated:YES];
}
AllContactsViewController.h
@interface AllContactsViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>
AllContactsViewController.m
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdent = @"ContactCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdent];
if (cell == nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdent];
}
NewContact *tempContact = [[NewContact alloc]init];
tempContact = [self.allContactsArray objectAtIndex:[indexPath row]];
cell.textLabel.text = tempContact.firstName;
NSLog(@"%@", tempContact.firstName);
NSLog(@"Test......");
cell.imageView.image = tempContact.contactPicture;
[tableView reloadData];
return cell;
}
ノート:
AllContactsViewController
からサブクラス化されていることがわかりますが、デリゲートとデータソースを適切に設定したにもかかわらずUIVIewController
、からサブクラス化する必要がありますか?UITableViewController