【发布时间】:2014-09-09 00:43:58
【问题描述】:
我试图让我的 UITableViewCell 在其 textLabel 中显示正确的文本,但到目前为止没有显示任何文本。我试图对数组进行 NSLOG 以确保它有数据并且确实有。我尝试遍历数组并从我正在获取的核心数据实体中的每个条目中打印文本,然后我得到了我想要的文本。在单元格中显示所有这些信息时,什么也没有发生。我还注意到 cellForRowAtIndexPath 方法也没有被调用。
首先是从 UIAlertView 按钮转换视图的方式。
-(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];
}
}
这里是 cellForRowAtIndexPath 方法。
- (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;
}
编辑:
这里是委托方法
- (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;
}
我现在注意到的问题是数据源数组将记录其内容,但 numberOfRowsInSection 返回的计数为 0。
这是视图最初是如何启动和转换的。这段代码来自最初的 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];
}
}
【问题讨论】:
-
属性检查器中有什么? (顶部列表中的第四个图标)
-
这不是归因。第一个字段显示“内容:动态原型”的那个
-
我重新编辑了截图,这些是你要找的面板吗?
-
好的。一切看起来都很好。你说 numberOfSections 和 numberOfRowsInSection 被调用,你返回 >0?
-
有一个窗口,其中 numberOfRows = 0,但是我确实在 viewDidAppear 中调用 [self.tableView reloadData]
标签: ios objective-c uitableview