【问题标题】:didSelectRowAtIndexPath really doesn't workdidSelectRowAtIndexPath 真的不起作用
【发布时间】:2012-08-22 07:00:36
【问题描述】:

didSelectRowAtIndexPath 不起作用。
我是否配置了 2 个代表。一切都已链接(tableview、tableviewcell)。
已经删除了,又做了一次。
我在这里搜索了所有内容,但没有任何效果。
我认为这是最好的link 之一,但仍然无济于事。

我最后的希望是,我正在为模态打开我的 ViewController,其中有这个 tableview。但这将是非常错误的问题。

除此之外,我需要一些帮助

Somo 码 .H

@interface simulator : UIViewController <UITableViewDelegate, UITableViewDataSource, UIScrollViewDelegate>
{
   NSArray                                          *array_products;
}
@property (nonatomic, strong) NSDictionary          *plist_products;
@property (nonatomic, strong) IBOutlet UITableView  *table_menu_left;
@property (nonatomic, strong) NSString              *file_plist;

@end

一些代码.M

#import "cel_products.h"

- (void)viewDidLoad
{
   NSString *path_root      = [[NSBundle mainBundle] bundlePath];
   NSString *full_path      = [path_root stringByAppendingPathComponent:self.file_plist];
   self.plist_products      = [[NSDictionary alloc] initWithContentsOfFile:full_path];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
   static NSString *CellIdentifier = @"id_cell_products";
   UITableViewCell *cell           = [self.table_menu_left dequeueReusableCellWithIdentifier:CellIdentifier];

   array_products                  = [self.plist_produtcs allKeys];
   if (cell == nil)
   {
       NSArray *topLevelObjects    = [[NSBundle mainBundle] loadNibNamed:@"cel_products" owner:self options:nil];

       for(id currentObject in topLevelObjects)
       {
           if([currentObject isKindOfClass:[cel_products class]])
           {
               cell = (cel_products *)currentObject;
               break;
           }
       }
   }
   cell.textLabel.text       = [array_products objectAtIndex:indexPath.row];
   return cell;
}

// numberofrowsinsection - OK
// numberofsectionintableviw - OK

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
   NSLog(@"Hein?????");
   // Nothing..........
}

【问题讨论】:

    标签: objective-c uitableview didselectrowatindexpath


    【解决方案1】:

    您在didSelectRowAtIndexPath 设置了休息时间吗?试试看它是否在那里成功破解。

    扩展rokjark 的答案,您必须手动将委托和数据源设置为相关文件。

    您的头文件 simulator.h 只是将其声明为 SOME UITableView 的 A 委托/数据源。

    您仍然需要指向 table_menu_left 以使用 simulator.h 作为 THE 委托文件来处理它的所有回调。

    设置:

    self.table_menu_left.delegate = self;
    self.table_menu_left.datasource = self;
    

    再次在didSelectRowAtIndexPath 中设置一个中断,看看它是否被调用。

    【讨论】:

    • 我设置了一个刹车,并没有进入这个方法。所有代表均已设置,所有 IB 连接器均已设置。我有 4 个应用程序使用这个 tableview 代码的相同方案,所有工作都很完美,其中 1 个在相同的代码上使用 2 个 tableviews,工作完美。这个项目的唯一区别是,以模态方式打开视图。只是那是不同的。非常有线!!!
    • 所以你是通过模态segue打开视图?您是否在要从中进行切换的视图中的 prepareForSegue 中正确设置了委托(或委托,如果您有多个 UITableViews)?
    • 我不使用历史板...但我用解决方案回答 ;)
    【解决方案2】:

    我谦虚地向所有人道歉! 我无意中点击了 Attributes Inspector> 选择:NO SELECTION

    所以我在代码中找不到任何东西。

    再次,我向大家道歉,但如果有人遇到这个问题,这是一个需要验证的步骤。 " Change to Attributes Inspector> 选择:SINGLE SELECTION or MULTIPLE SELECTION(由你决定)

    感谢大家的回答和帮助

    【讨论】:

    • 请回答您自己的问题!像这样的问题一直悬而未决,没有答案。
    猜你喜欢
    • 2012-09-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-22
    • 1970-01-01
    相关资源
    最近更新 更多