I know this question been asked before but i haven't found an answer for this particular problem. i have been followed the apple-tutorial step-by-step but i cant see my data on the table view.
The problem is that the func "cellForRowAtIndexPath" never been called although numberOfSectionsInTableView return 1 and numberOfRowsInSection also return.
here is my code:
#import "StudentListTableViewController.h"
#import "Student.h"
@interface StudentListTableViewController ()
@end
@implementation StudentListTableViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self loadInitialData];
NSLog(@"yes");
// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
NSLog(@"NUMBERS OF SECTION IN TABLE");
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
NSLog(@"NUMBER OF ROWS");
return self.studentList.count;
}
-(void) loadInitialData
{
NSLog(@"LOAD INITIAL DATA");
self.studentList = [[NSMutableArray alloc] init];
Student* s1 = [[Student alloc] init];
s1.firstName = @"moses";
s1.lastName = @"gonzales";
s1.phoneNumber = @"050-20202020";
s1.studentID = @"90123456";
/* Student* s2 = [[Student alloc] init];
s2.firstName = @"roman";
s2.lastName= @"wolf";
s2.phoneNumber = @"050123456789";
s2.studentID = @"39393939";
*/
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"prototypeCell" forIndexPath:indexPath];
NSLog(@"fcell");
// Configure the cell...
Student* s = [self.studentList objectAtIndex:indexPath.row];
cell.textLabel.text = s.firstName;
return cell;
}
Peace :)
Your self.studentList
is empty array, therefore it return 0 as count. If UITableView
has 0 section than it will not call its cellForRowAtIndexPath:
. Try to change your loadInitialData
method.(Add s1
to the self.studentList).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.