设置:
MainViewController持有一个NSMutableArray对象。对象是 my 的一个实例,NewContact它有一个firstName和一个contactImageivar。当我点击时showAllContactsBtn,MainViewController AllContactsViewController应该在桌子上显示所有对象 ivars (firstNames和contactImages)。
我认为问题在于我没有正确地将数据传递给AllContactsViewController但无法弄清楚如何修复它。值得一提的是,我没有看到其中的 NSLog语句,cellForRowAtIndex所以可能根本不会调用该方法?
主视图控制器.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尽管我正确设置了委托和数据源?