ios - UITableViewController 中 numberOfRowsInSection 中的 section 值始终为 1
<p><p>我在 tableview 中有两个部分位于 tableviewcontroller 内
由于某种原因,方法 numberOfRowsInSection 中的部分值始终为“1”。这很奇怪,因为一切似乎都很好。</p>
<pre><code>- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
int i=section;
if(section==0)
return 1;
else{
return ;
}
}
</code></pre>
<p>在 Storyboard 中,我有一个包含两个部分的表格</p>
<p>好的,再次为您理解问题。看这段代码</p>
<pre><code>- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
NSLog(@"Section: %d",(int)section);
if(section==0)
return 1;
else{
return ;
}
}
</code></pre>
<p>在日志中我总是看到“1”
那是什么?很奇怪</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>我不明白这背后的原因,因为我也是初学者,但就我而言,我认为你第一次尝试返回 1 行,下一步你想返回flightDetailsArray 的计数,所以也许您可以通过以下步骤实现:-</p>
<pre><code>- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
static int i=0
if(i==0)
return 1;
i++;
else{
return ;
}
}
</code></pre></p>
<p style="font-size: 20px;">关于ios - UITableViewController 中 numberOfRowsInSection 中的 section 值始终为 1,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/38654669/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/38654669/
</a>
</p>
页:
[1]