Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.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
Ios 单击目标C中的UITableViewCell时发生的事件?_Ios_Objective C_Uitableview - Fatal编程技术网

Ios 单击目标C中的UITableViewCell时发生的事件?

Ios 单击目标C中的UITableViewCell时发生的事件?,ios,objective-c,uitableview,Ios,Objective C,Uitableview,我在项目中遇到如下问题: 我编写了一个类,它是UIView的子类,具有: 1-按钮 2-表格视图 3-文本字段 我已经创建了该类的一个对象,并将该对象添加到uiviewcontroller的视图中。当我点击按钮,使表格视图显示所有国家的列表,然后点击表格视图的一个单元格,文本字段将获得单元格的值。我想在触摸tableview的单元格时检测事件。我该怎么做?请帮帮我,提前谢谢 p/S:tableview是contentView的子视图。层次结构如下: 视图控制器-滚动视图-内容视图-(视图1、视

我在项目中遇到如下问题:

我编写了一个类,它是UIView的子类,具有:

1-按钮

2-表格视图

3-文本字段

我已经创建了该类的一个对象,并将该对象添加到uiviewcontroller的视图中。当我点击按钮,使表格视图显示所有国家的列表,然后点击表格视图的一个单元格,文本字段将获得单元格的值。我想在触摸tableview的单元格时检测事件。我该怎么做?请帮帮我,提前谢谢

p/S:tableview是contentView的子视图。层次结构如下:

视图控制器-滚动视图-内容视图-(视图1、视图2…)


正如人们在评论中所说,您所需要的只是
委托
数据源
。如果要以编程方式完成所有工作,则需要向代码中添加许多内容,例如
,并在
viewDidLoad
上调用它们。然后您需要实现一些方法。苹果有大量关于所有类和方法的文档,看看吧。您需要
didSelectRowAtIndexPath


希望我能帮助你

UITableView
有了委托协议,并且为了你的需要,你只需要实现

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
您将通过
indepath
知道您点击的位置,因此您知道位置,然后您可以做任何您想做的事情

如果要获取相应的单元格,请使用

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

只需将
indepath
didselectrowatinedexpath
传递到
cellforrowatinedexpath
这就是您想要做的吗

你没给我密码什么的。。所以,这只是我对你尝试的假设。。嗯

请给我们更多的细节。。。如有必要,请编辑您的问题

//viewController.h

@interface viewController : UIViewController

@property (nonatomic) NSMutableArray *selectedIndexs; 

// use this array as your dataSource for the secondTableView (popup tableView?)

@end

//viewController.m

@implementation viewController

// codes..
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    /*
        you need to store the countries indexPath to cell the name/details
        in this example i will just get the `.textLabel.text`
    */

    UITableViewCell *cell  = [tableView cellForRowAtIndexPath:indexPath/*current selected indexPath*/];

    if ([self.selectedIndexs containsObject:cell.textLabel.text]) 
    {
        // [self.selectedIndexs removeObject:cell.textLabel.text]; ]> delete if already in the array

        // return; ]> if you dont want to remove the object just return..
    }
    else
        [self.selectedIndexs addObject:cell.textLabel.text]; // add the country if not exist in the array

}

- (void)showSelectedCountries:(UIButton *)sender //this is the number 1 from the image (Button)
{
    UIView *customViewForSelected = [[UIView alloc] init];

    // then if you have declared a property for `dataSource` inside your 'customViewForSelected' just:

    customViewForSelected.yourSelectedsDataSource = selectedIndexs;

    // then show the view with the table inside which contains only the table.. correct?

    [self.view addSubview:customViewForSelected]; // i just added as subview because i dont know how you call it..
}

@end

希望你会觉得这很有帮助。。干杯。

我创建了一个类:
DropdownListViewCountries
UIView
的子类,包括一个
按钮、一个文本字段和一个tableview

@interface DropdownListViewCountries : UIView<UITextFieldDelegate, UITableViewDelegate>
@interface DropdownListViewCountries:UIView
.在
@implementation DropdownListViewCountries
中,我实现了
didSelectRowAtIndexPath
然后我创建了类:
IndividualPersonalData
UIViewController
的子视图。此类包含进度视图栏。 然后我创建了一个DropdownListViewCountries对象,并将其添加到
IndividualPersonalData

如何触摸
tableview
的单元格以更改进度视图值

谢谢大家的帮助。现在,出于我的目的,我找到了以下用于检测事件的代码:

[self.firstDropdownListView.countriesTextField addObserver:self forKeyPath:@"text" options:0 context:nil];


- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
    if([keyPath isEqualToString:@"text"] && object == self.firstDropdownListView.countriesTextField)
    {
        // text has changed
        LogDebug(@"HELLO WORLD");
    }
}

您应该阅读UITableViewDelegate协议。您需要的方法就在那里。感谢rdelmar,我在my class-uiview中执行了UITableViewDelegate协议的方法,我可以检测该类中的事件。但我想,例如:触摸一个单元格,该图像顶部进度条的进度值将增加/减少。你能给我提个建议吗?@VienVu>给我们看一些code.file自定义class.h和.m4-进度视图栏如下:谢谢Leonardo。我在自定义类中执行了didSelectRowAtIndexPath,但我需要做什么会影响viewcontroller中的进度视图栏。进度视图栏是视图控制器中视图的子视图-0中的编号4。我在自定义类中执行了didSelectRowAtIndexPath,但我需要如何做才能影响视图控制器中的进度视图栏?。进度视图栏是postimg.org/image/g6llkhoub/6050f54fif中视图控制器(编号4)中视图的子视图。如果是您的视图控制器实现了
didselectrowatinexpath
,您可以通过self.view(self是视图控制器)和其他视图控制器属性访问子视图。因此,如果进度条被定义为视图控制器的属性,只需调用self.progressBar并获取对象,现在就可以应用逻辑更新视图。在uiview的子视图“我的自定义类”中实现了didSelectRowAtIndexPath,不是viewcontroller。我想从uiviewcontroller触摸tablview的一个单元格,它会影响进度视图栏。我该怎么做?那么您的问题是,如何从UIView访问视图控制器。这是另一个需要回答的大问题,你需要谷歌。但我觉得你需要重新考虑你的应用程序的结构。但是,至少可以将进度条的引用添加到视图中。或者使用一些共享对象传递UIView和控制器,如appDelegate。有很多方法