gpt4 book ai didi

ios - 在 Today 扩展中添加 UITableView

转载 作者:行者123 更新时间:2023-11-29 02:24:47 25 4
gpt4 key购买 nike

我是 iOS 新手。

我想使用 Today 扩展。我创建了 Today 扩展并添加了 uitableview 它工作正常。但是当我尝试选择行时,委托(delegate)方法 DidSelectRowAtIndexPath 不会调用。

在我的代码中有 uitableview 委托(delegate)和数据源的 3 个方法。

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 3;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyIdentifier"];

if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"MyIdentifier"];
}

cell.textLabel.text = [NSString stringWithFormat:@"Hello World%li",(long)indexPath.row];
return cell;

}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}

以上数据源方法调用正确

但是 didselect row 方法不会在选择行后调用。

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"row Selected");
}

感谢您的帮助。

最佳答案

您提到调用了数据源方法。但是 tableView: didSelectRowAtIndexPath: 是一个 UITableViewDelegate 方法,而不是数据源方法。看起来 TableView 的 delegate 属性可能未设置。

关于ios - 在 Today 扩展中添加 UITableView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27685762/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com