【问题标题】:UITableView unresponsive to gestures and not populating cells with dataUITableView 对手势没有响应并且没有用数据填充单元格
【发布时间】:2015-08-24 12:58:13
【问题描述】:

我以编程方式创建了一个 UITableView 并设置了它的所有属性,但我的 NSMutableArray 中的数据不会填充单元格,并且在点击时单元格不会执行任何操作。任何见解表示赞赏,谢谢!

克莱顿

- (void)viewDidLoad {
    [super viewDidLoad];

    [self.view setBackgroundColor:[UIColor whiteColor]];
    list = [[UITableView alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height * .3333, self.view.bounds.size.width, self.view.bounds.size.height * .6667) style:UITableViewStylePlain];

    list.delegate = self;
    list.dataSource = self;
    list.backgroundColor = [UIColor magentaColor];
    list.scrollEnabled = YES;
    list.userInteractionEnabled = YES;
    list.multipleTouchEnabled = YES;
    list.hidden = NO;

    [self.view addSubview:list];
    [self.view bringSubviewToFront:list];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [favorites count];
}

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

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *Cell = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:Cell];

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

    cell.textLabel.text = [[global sharedInstance].favorites objectAtIndex:indexPath.row];
    cell.textLabel.textColor = [UIColor blackColor];
    cell.userInteractionEnabled = YES;
    cell.hidden = NO;
    cell.multipleTouchEnabled = YES;
    [self.view bringSubviewToFront:cell];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    NSLog(@"selected %ld row", (long)indexPath.row);
}

【问题讨论】:

  • favorites 不是nil?里面有东西吗?
  • @rmaddy 它改变了。它可以,但不是必须的。不管结果是否相同。
  • 如果favoritesnil 或为空,则该表将没有行。很简单。当favorites 有项目时,表是空的吗?
  • 是但不应该是,这才是重点。
  • 这是什么?请说清楚。

标签: ios objective-c uitableview


【解决方案1】:

知道了,谢谢,问题在于数据从我的收藏夹单例数组传输到我的本地数组(以前是空的)。非常感谢:)

【讨论】:

    【解决方案2】:

    在 viewDidLoad 方法的最后,添加这个:

    [列表重载数据];

    【讨论】:

      猜你喜欢
      • 2012-05-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多