2013-07-30 100 views
0

我在iPhone定制的电池,其具有具有我想改变图像视角的图像时,我对这里的按钮按下一个按钮,图像视图是我的按钮代码如何更改单元格的图像?

-(void)btnLikePressed:(UIButton *)sender{ 

    imageDC *objMenu = [dataArray objectAtIndex:sender.tag]; 
    GET_DBHANDLER 
    [dbHandler performSelector:@selector(like_image:) withObject: objMenu.image_id]; 


} 
+1

是什么'performSelector您的tableView细胞:withObject:'服务对于?为什么不简单地使用'[dbHandler like_image:objMenu.image_id]'?此外,Objective-C中的命名约定如下所示:方法和变量名称使用camelCaps。 '[dbHandler likeImage:objMenu.imageID]'。 – 2013-07-30 05:57:28

+0

是你的问题解决了> – Rajneesh071

回答

0

要你的方法,找出您的确切指标UITableViewCell,请使用以下命令: -

CGPoint point = [sender convertPoint:CGPointZero toView:_iTableView]; 
NSIndexPath *indexPath = [_iTableView indexPathForRowAtPoint:point]; 

你会得到你的indexpath。从这里你可以识别你的UIImageView,希望你给他们的标签,然后改变图像。

+0

不工作铁 –

+0

什么不工作? – IronManGill

0

下面的步骤将工作: -

  1. 标记您的ImageView的。
  2. 使用该代码的cellForRowAtIndexPath

    NSArray *nib; 
    static NSString *cellIdentifier= @"cell"; 
    
    UITableViewCell *theCell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; 
    
    
    if(theCell== nil) 
    { 
        { 
         nib = [[NSBundle mainBundle] loadNibNamed:<Your cellNibName> owner:self options:nil]; 
        } 
        theCell = [nib objectAtIndex:0]; 
        theCell.selectionStyle = UITableViewCellSelectionStyleNone; 
        // theCell.selectionStyle = UITableViewCellSelectionStyleBlue; 
    } 
    
    UIImageView *imageView=(UIImageView*)[[theCell contentView] viewWithTag:<Your tag>]; 
    

    //你想和ImageView的

  3. 你让图像视图裁判做你想做的什么都。

+0

我在自定义单元格上有图像视图@amar –

+0

是为自定义单元格添加一个单独的.xib文件,并且将其加载到该单元格中,这不是什么新功能,我们每天都会这样做非常基本。 – amar

+0

采取一个空的userinterface添加一个tableview单元格它定制它并标记各种组件 – amar

0

在UITableViewDataSource功能

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 

而设置电池只需添加标签到您的按钮和ImageView的为好。

cell.yourBtn.tag = indexPath.row; 
cell.imageView.tag = indexPath.row + 1000(any number); 
现在

在你的UITableViewController类

现在当按钮用户点击你的按钮,标签,实际上是你的行数和ImageView的(BTN标签+ 1000)的标签,以及你可以得到的ImageView通过使用相同的信息。

-(void)btnLikePressed:(UIButton *)sender{ 

    NSInteger btnTag = [sender tag]; 
    UIImageView *imageView = [yourTableView viewWithTag:btnTag + 1000]; 
    // here your code by using imageView  
} 
+0

我怎样才能访问按钮点击事件中的图像视图 –

+0

@iOSdeveloper我已经更新了我的答案,请参阅。 – Suryakant

0

试试这个娄代码

-(void)btnLikePressed:(UIButton *)sender{ 

    static NSString *CellIdentifier = @"yourCellName"; 

    UITableViewCell *cell=(UITableViewCell*)[[sender superview] superview]; 

    UITableView *tableView=(UITableView*)[cell superview]; 
    NSIndexPath *path=[tableView indexPathForCell:cell]; 


    yourCellName *selectedCell = (yourCellName*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    [selectedCell.imageView.image setImage:[UIImage imageNamed:@"yourImageName.png"]]; 
} 
+0

不工作Paras joshi –

0

先给tagValue您的ImageView,就像你给5到您的ImageView。 然后在buttonClick上访问它。

-(void)btnLikePressed:(UIButton *)sender 
{ 
    UITableViewCell *cell=(UITableViewCell*)[sender superview]; 

    UIImageView*imageView=(UIImageView*)[cell viewWithTag:5]; 

    //Now do whatEver you want to do with your imageview 
} 

编辑

,如果您添加的ImageView作为

[cell.contentView addSubview:imageView]; 

然后得到这样

UITableViewCell *cell=(UITableViewCell*)[[sender superview] superview]; 
相关问题