首先,我是 iOS 的新手,这是我的第一个项目,第一个问题出现了。我的问题解释如下。
我有一个包含两个部分的 tableView。问题是,当我向上滚动 tableView 时,除了第一节标题之外的整个 tableView 向上移动。但是向下滚动时没有问题。
我的代码是:
//----------------Table view delegate method numberOfSectionsInTableView.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 2;
}
//----------------Table view delegate method numberOfRowsInSection.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (section==0)
{
return [tableSection1 count];
}
else
{
return [tableSection2 count];
}
}
//----------------Table view delegate method titleForHeaderInSection.
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
if(section==0)
{
return @"Mandatory Details";
}
else
{
return @"Optional Details";
}
}
//----------------Table view delegate method cellForRowAtIndexPath.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"SimpleTableItem";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: simpleTableIdentifier];
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:simpleTableIdentifier];
if(indexPath.section==0)
{
// Set the data for this cell:
cell.textLabel.text = [tableSection1 objectAtIndex:indexPath.row];
cell.detailTextLabel.text = [tableSection1Subtitle objectAtIndex:indexPath.row];
}
if(indexPath.section==1)
{
// Set the data for this cell:
cell.textLabel.text = [tableSection2 objectAtIndex:indexPath.row];
cell.detailTextLabel.text = [tableSection2Subtitle objectAtIndex:indexPath.row];
}
return cell;
}
//---------------Table view delegate method didSelectRowAtIndexPath.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
if(indexPath.section==0)
{
if(indexPath.row==0)
{
//....my code here....
}
if(indexPath.row==1)
{
//....my code here....
}
if(indexPath.row==2)
{
//....my code here....
}
if(indexPath.row==3)
{
//....my code here....
}
}
if(indexPath.section==1)
{
if(indexPath.row==1)
{
//....my code here....
}
if(indexPath.row==2)
{
//....my code here....
}
if(indexPath.row==3)
{
//....my code here....
}
}
}
因此,从我的代码来看,第 0 节标题,即“强制详细信息”,并没有根据整个 tableView 的移动向上移动。第 0 部分在视图顶部停止,而 tableView 的其余部分即使在视图顶部之后也会向上移动。但是,如果我们向下滚动,即使对于第 0 节,表格视图中的任何其他组件也没有其他问题。
请帮我。它对每个人来说都像是一个错误。所以我被我的领导解雇了。请帮助我。