iphone - 我们如何让 UITable 中的部分标题可触摸?
<p><p>我想让它喜欢,触摸部分标题,然后跳到本部分的末尾。我怎么能做到?有什么建议么?干杯</p>
<pre><code>- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *headerView = [[ initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 30)] autorelease];
colorWithAlphaComponent:0.7]];
UILabel *titleInSection = [[ initWithFrame:CGRectMake(50, 3, tableView.bounds.size.width/3, 20)] autorelease];
colorWithAlphaComponent:0]];
];
if (isSectionLoad == YES){
;
titleInSection.text = ;
}
titleInSection.tag = section;
UITapGestureRecognizer *recognizer = [ initWithTarget:self action:@selector(sectionTapped:)];
;
;
;
return headerView;
}
- (IBAction)sectionTapped:(UITapGestureRecognizer *)recognizer
{
switch (recognizer.view.tag) {
case 0:
// do what you want for section with index 0
NSLog(@"HELLO WORLD!!!");
break;
default:
break;
}
}
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>在您的委托(delegate)中实现方法 <code>- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section</code>。在此方法中,创建带有必要 subview (标签、图像等)的 <code>UIView</code>。最后只需将 <code>UITapGestureRecognizer</code> 添加到该 View 。然后把它还回去。</p>
<p>例如:</p>
<pre><code>- (IBAction)sectionTapped:(UITapGestureRecognizer *)recognizer
{
switch (recognizer.view.tag) {
case 0:
// do what you want for section with index 0
break;
default:
break;
}
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UILabel *label;
label.text = ;
label.tag = section;
UITapGestureRecognizer *recognizer = [ initWithTarget:self action:@selector(sectionTapped:)];
;
;
returnlabel;
}
</code></pre></p>
<p style="font-size: 20px;">关于iphone - 我们如何让 UITable 中的部分标题可触摸?,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/7307337/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/7307337/
</a>
</p>
页:
[1]