我有兩個關於內容視圖的問題。我如何知道哪些內容視圖被觸動?
1問題: 有在的tableview細胞兩個內容的意見。我怎麼知道哪一個被觸動?
第二個問題: 我只想內容視圖顯示在tableview中的第一部分。 但是,當我向上滾動tableview時,內容視圖也出現在第三節中。 我該如何解決這個問題?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
UIImageView *imgView, *imgView1;
if(cell == nil)
{
if (indexPath.section == 0) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
cell.textLabel.text = @"test";
imgView = [[UIImageView alloc] initWithFrame:CGRectMake(100,0,20,62)];
[imgView setImage:[UIImage imageNamed:@"1.png"]];
imgView.tag = 10;
[cell.contentView addSubview:imgView];
[imgView release];
imgView1 = [[UIImageView alloc] initWithFrame:CGRectMake(200,0,20,62)];
[imgView1 setImage:[UIImage imageNamed:@"2.png"]];
imgView1.tag = 20;
[cell.contentView addSubview:imgView1];
[imgView1 release];
}
}
else
{
if (indexPath.section == 0) {
imgView = (id)[cell.contentView viewWithTag:10];
imgView1 = (id)[cell.contentView viewWithTag:20];
}
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
// How do I know left content view is touched or right content view is touched?
}
請告訴我的代碼。我是初學者。 – user698200
更新了我的答案。 1)在Apple文檔中搜索UIGestureRecognizer,這很簡單。 2)看起來更新文字 – Nekto
謝謝。第二個問題解決了。我認爲如果我知道哪個視圖被觸摸,就使用UIGestureRecognizer。 – user698200