#import "AssignmentsViewController.h"
#import "Assignment.h"
@interface AssignmentsViewController ()
@property NSMutableArray *assignments;
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@end
@implementation AssignmentsViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
NSLog(@"viewDidLoad");
[super viewDidLoad];
// Do any additional setup after loading the view.
self.assignments = [[MySingleton sharedMySingleton] assignments];
self.tableView.delegate = self;
self.tableView.dataSource = self;
}
- (void)viewWillAppear:(BOOL)animated {
NSLog(@"viewWillAppear");
[self.tableView reloadData];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
NSLog(@"numberOfSectionsInTableView");
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSLog(@"numberOfRowsInSection");
return [self.assignments count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"cellForRowAtIndexPath");
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"AssignmentCell"];
if(cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"AssignmentCell"];
}
cell.textLabel.text = [[self.assignments objectAtIndex:indexPath.row] title];
return cell;
}
@end
加载 AssignmentsViewController 并且至少一个作业分配在 assignments 数组中时的控制台输出:
2013-11-06 18:55:09.396 Homework Planner[4756:70b] viewDidLoad
2013-11-06 18:55:09.403 Homework Planner[4756:70b] numberOfSectionsInTableView
2013-11-06 18:55:09.405 Homework Planner[4756:70b] numberOfRowsInSection
2013-11-06 18:55:09.408 Homework Planner[4756:70b] viewWillAppear
2013-11-06 18:55:09.409 Homework Planner[4756:70b] numberOfSectionsInTableView
2013-11-06 18:55:09.409 Homework Planner[4756:70b] numberOfRowsInSection
我正在制作一个显示用户家庭作业的应用程序。出于某种原因,从未调用 cellForRowAtIndexPath,即使我确定 assignments 数组中有一个作业分配对象。作业分配通过模态视图添加到数组中,我已经验证它们确实是由该过程添加的,并且在用户点击“取消”后,视图返回到此类定义的视图。当这种情况发生时,其他两个与 UITableView 相关的方法运行,但不是 cellForRowAtIndexPath。请帮我解决我遇到的这个问题。