2014-09-01 109 views
0

我已经包含在NSMutableDictionnary产品的列表,我diplsay它是这样的:检测点击的UITableView

http://imgur.com/rKA2yvA

现在,我想补充一个观点每一个产品。如果我点击“紫苏”对于为例我要切换视图,并有一个新的观点,产品细节或别的东西..

我添加以下代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
     static NSString *simpleTableIdentifier = @"SimpleTableItem"; 

UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier forIndexPath:indexPath]; 

// Configure the cell... 
NSString *sectionTitle = [aromaSectionTitles objectAtIndex:indexPath.section]; 
NSArray *sectionAroma = [tableData objectForKey:sectionTitle]; 
NSString *aromaLabel = [sectionAroma objectAtIndex:indexPath.row]; 
cell.textLabel.text = aromaLabel; 

if (cell == nil) { 
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier]; 
} 
cell.textLabel.userInteractionEnabled = YES; 
cell.textLabel.tag = indexPath.row; 

UITapGestureRecognizer *tapped = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(buttonPressed:)]; 
tapped.numberOfTapsRequired = 1; 
[cell.textLabel addGestureRecognizer:tapped]; 
return cell; 
} 


-(void)buttonPressed :(id) sender { 
UITapGestureRecognizer *gesture = (UITapGestureRecognizer *) sender; 
NSLog(@"Tag = %ld", (long)gesture.view.tag); 
} 

在我的日志ID,但它不是唯一的,id是产品的行号,这里Armoise将是0,ArbreThé1,但是Basilic将是0并且Baie将会是1等等。 我该如何创建根据用户的选择查看?

非常感谢您的帮助!

+0

你只是想要一个细胞是可点击?有一个委托方法。 tableView:didSelectRow:atIndexPath: – CW0007007 2014-09-01 12:46:05

+0

我想在描述产品的视图上重定向用户 – 2014-09-01 12:50:20

回答

3

可以使用的UITableViewDelegate方法

//表的观点是选择一个单元

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 
    //Your Code here 
} 
+0

因此,我将能够显示描述所选产品的视图? – 2014-09-01 12:50:50

+0

是在这个方法中,你推新的viewcontroller。或者你可以隐藏取消隐藏其他视图 – BHASKAR 2014-09-01 12:52:24

+0

而我该如何知道用户选择哪个产品。例如,您点击Basilic,在我的新视图中,我想展示一个basilic的图像,让我们说价格,我不想为每个产品创建视图,我希望它是自动的。可能吗 ? – 2014-09-01 12:54:52