Im trying to get my UITableViewCell to display the proper text in its textLabel but so far no text is being displaying. I have tried to NSLOG the array to make sure that it has data and it does. I have tried going through the array and printing the text from each entry from my Core Data entity that I am fetching and I get back the text that I want. When it comes to displaying all that info in the cell nothing happens. I also notice that the cellForRowAtIndexPath method is also not being called.
Here is how the view is transitioned in the first place, from a UIAlertView button.
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
if ([title isEqualToString:@"Corp"]){
DeckBuilderTableViewController *deckBuilder = [[DeckBuilderTableViewController alloc]init];
[deckBuilder fetchCorpCards];
[self performSegueWithIdentifier:@"deckBuilder" sender:self];
}
if ([title isEqualToString:@"Runner"]){
DeckBuilderTableViewController *deckBuilder = [[DeckBuilderTableViewController alloc]init];
[deckBuilder fetchRunnerCards];
[self performSegueWithIdentifier:@"deckBuilder" sender:self];
}
}
Here is the cellForRowAtIndexPath method.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"cellForRowAtIndexPath called");
NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
// Configure the cell...
if (self.corpCardsSelected == YES){
CorpCard *corpCards = [self.datasource objectAtIndex:indexPath.row];
cell.textLabel.text = corpCards.title;
}
if (self.runnerCardsSelected == YES){
RunnerCard *runnerCards = [self.datasource objectAtIndex:indexPath.row];
cell.textLabel.text = [NSString stringWithFormat:@"%@", runnerCards.title];
}
return cell;
}
EDIT:
here are the delegate methods
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return self.datasource.count;
}
The problem that I am noticing now is that the datasource array will log its contents, but numberOfRowsInSection returns a count of 0.
Here is how the view is initiated and transitioned to in the first place. This code is from the initial viewController.
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
if ([title isEqualToString:@"side1"]){
DeckBuilderTableViewController *deckBuilder = [[DeckBuilderTableViewController alloc]init];
[deckBuilder fetchSide1Cards];
[self performSegueWithIdentifier:@"deckBuilder" sender:self];
}
if ([title isEqualToString:@"side2"]){
DeckBuilderTableViewController *deckBuilder = [[DeckBuilderTableViewController alloc]init];
[deckBuilder fetchSide2Cards];
[self performSegueWithIdentifier:@"deckBuilder" sender:self];
}
}
if cellForRowAtIndexPath
is not being called it's either because the delegate
is not set correctly, which you seem to have or number of sections and/or rows is incorrect. Make sure you are returning correct values in these methods:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
//should return at least 1
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
//should return at least 1
您的dataSource和代表出口应设置为表视图控制器,而不是表视图。
Since your datasource has a count at one point, but 0 at another, it's pretty clear you're zeroing it out. Check your view[Will|Did]Appear methods to make sure you're not fetching data a second time, and doing it incorrectly.
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.