Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/100.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone iTableViewCell内的UIButton的iAction_Iphone_Uitableview_Ibaction - Fatal编程技术网

Iphone iTableViewCell内的UIButton的iAction

Iphone iTableViewCell内的UIButton的iAction,iphone,uitableview,ibaction,Iphone,Uitableview,Ibaction,我在Interface Builder中创建了一个UITableViewCell,并在其中添加了一个UIImageView和一个UIButton。我已经给了UIButton一个插座,并将其连接到一个iAction上,带有内部事件集的润色。我假设它会调用这个方法,因为一切看起来都是连接在一起的: - (IBAction)pressedCheckbox:(id)sender { [sender setBackgroundImage:[UIImage imageNamed:@"checked.

我在Interface Builder中创建了一个UITableViewCell,并在其中添加了一个UIImageView和一个UIButton。我已经给了UIButton一个插座,并将其连接到一个iAction上,带有内部事件集的润色。我假设它会调用这个方法,因为一切看起来都是连接在一起的:

- (IBAction)pressedCheckbox:(id)sender {
    [sender setBackgroundImage:[UIImage imageNamed:@"checked.png"] forState:UIControlStateNormal];
    NSLog(@"clicked check");

}
检查连接选项卡,我已正确设置所有内容,包括插座和操作。我没有收到任何错误,但在预览应用程序时,单击UITableViewCell中的按钮什么都不做,并且在日志中也看不到任何内容

为什么不让我点击UITableViewCell中的按钮

编辑:

cellForRowAtIndexPath的代码:

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

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
        cell.editingAccessoryType = UITableViewCellAccessoryDisclosureIndicator;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }

    if (indexPath.section == 0) {
        switch (indexPath.row) {
            case 0:
                cell = topCell;
                break;
            case 1: 
                cell = cell1;
                break;
        }//end switch

    }//end if

    return cell;
}

你在IB做这个吗?可能值得尝试
-(void)addTarget:(id)target action:(SEL)action for controlEvents:(UIControlEvents)controlEvents
(在所属视图控制器的loadView方法中)以查看问题是否出在IB链接上。

您的意思是这是UITableViewCell的子类,对吗?是否确实使用此单元格而不是普通的UITableViewCell


转到
cellforrowatinexpath
方法实现,并查找实例化单元格的行。确保它将实例化为调用的子类,而不是UITableViewCell。如果您感到困惑,请发布
codeforrowatinexpath
方法的代码,以便我们可以看到它。

我还发现了问题所在。我需要为细胞设置不同的高度,并使用:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {

     if (indexPath.section == 0) {

          switch (indexPath.row) {

               case 0:

                    return 26;

                    break;

          }//end switch

     }//end if

     return tableView.rowHeight; <-- I just added this and it fixed the issue

}
-(CGFloat)tableView:(UITableView*)tableView rowatinexpath的高度:(nsindepath*)indepath{
if(indexPath.section==0){
开关(indexPath.row){
案例0:
返回26;
打破
}//终端开关
}//如果结束

return tableView.rowHeight;我发布了代码。不,它不是一个子类,只是普通的UITableViewCell。哦,好吧,那么你是如何将UIButton添加到单元格中的?如果你是以编程方式进行此操作的,你可能想检查一下:我不是以编程方式进行此操作的,只是因为我的单元格中有很多不同的UI元素,而我我不想把它们放在IB中。所以,我只是在IB中创建了一个UITableViewCell,然后为它创建了一个插座,并为我想要使用它的单元格调用了该插座。请看下面的链接,其中介绍了如何创建自定义NIB并加载它:否,使用:[cell1Check addTarget:self action:@selector(pressedCheckbox:)forControlEvents:UIControlEventTouchUpInside];也不起作用。请不要返回“44”-而是返回tableView.rowHeight。它可能是44,但您永远不知道它是否会在将来的某些iOS中更改。对于“26”也一样-如果需要,获取某些内容的frame.size.height。感谢您的提示,我将更改它。