相关疑难解决方法(0)

iphone - didSelectRowAtIndexPath:仅在长按自定义单元格后才被调用

我正在创建一个基于表视图的应用程序.我为表创建了一个自定义表格单元格,其中包含2个标签,1个图像和1个按钮.表视图数据源方法正常工作.我正在为自定义单元格和视图控制器类使用xib,我将委托和数据源连接到文件的所有者.但问题是当我选择表格行时,didSelectRowAtIndexPath没有起火.如上所述,解雇它的唯一方法是按住电池约3-4秒.有谁知道为什么会这样?

谢谢你的任何指示......

这是我的表视图方法..

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

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

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    NewCustomCell *cell = (NewCustomCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {
        NSArray *nib=[[NSBundle mainBundle]loadNibNamed:@"NewCustomCell" owner:self options:nil];
        cell=[nib objectAtIndex:0];
    }

    Addons *addons1=[[Addons alloc]init];
    addons1= [finalAddonsArray objectAtIndex:indexPath.row];

    if (addons1.data == nil) {
        cell.ivCategory.image = [UIImage imageNamed:@"blogo.jpg"];
    }
    else
    {
        cell.ivCategory.image=[UIImage imageWithData:addons1.data];
    }

    cell.lblTitle.text = addons1.name;
    if (addons1.price == nil) {
        cell.lblPrice.text = …
Run Code Online (Sandbox Code Playgroud)

objective-c uitableview ios

34
推荐指数
1
解决办法
2万
查看次数

调用cellForRowAtIndexPath:是否实用?

我见过很多很多实施时,开发人员UITableViewDelegateUITableViewDataSource直接调用cellForRowAtIndexPath:要么:

1)检索单元格以获取它们存储在单元格中的模型元素:

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    MyCell *cell = (MyCell *)[tableView cellForRowAtIndexPath:indexPath];
    int secretCode = cell.secretCode;
    LaunchMissileViewController *vc = [[LaunchMissileViewController alloc] initWithSecretCode:secretCode];
    [self.navigationController pushViewController:vc];
}
Run Code Online (Sandbox Code Playgroud)

2)尝试设置单元格样式(这有明显的问题,但似乎很常见):

MyCell *cell = (MyCell *)[self cellForRowAtIndexPath:indexPath];
// or [tableView cellForRowAtIndexPat:indexPath];
cell.backgroundColor = [UIColor greenColor];
Run Code Online (Sandbox Code Playgroud)

它是安全的,使毯声明说:"只有框架应该不断打电话cellForRowAtIndexPath:"?或者是否有一个人们可能自称的实际原因?

uitableview ios

7
推荐指数
1
解决办法
3189
查看次数

标签 统计

ios ×2

uitableview ×2

objective-c ×1