【发布时间】:2013-08-12 02:54:18
【问题描述】:
我正在创建一个基于表格视图的应用程序。我为表格创建了一个自定义表格单元格,其中包含 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 = nil;
}
else{
cell.lblPrice.text = [NSString stringWithFormat:@"%@ rs",addons1.price];
}
[cell.button addTarget:self
action:@selector(editButtonPressed:)
forControlEvents:UIControlEventTouchUpInside];
cell.button.tag=indexPath.row;
index = indexPath;
cell.selectionStyle = UITableViewCellSelectionStyleGray;
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"sjcjksbcjksbcfkebscf1234567890");
}
我得到的另一件事是,如果我使用默认 UITableViewCell 而不是自定义单元格,那么我的问题也是一样的,委托方法不会触发。
自定义单元格属性:
【问题讨论】:
-
didSelectRowAtIndexPath方法在哪里? -
你为什么确定它被解雇了?您是否绝对确定这需要 3-4 秒,还是您期望的操作仅在那时发生?在 didSelectRowAtIndexPath 的第一行添加一个 NSLog 或断点。另外 - 单元格中按钮的大小是多少?
-
@nikhita我正在使用 didSelectRowAtIndexPath 方法更新我的问题。
-
如果您从 didSelectRowAtIndexPath 推送视图控制器,我认为 nextViewcontroller 从 Web 服务加载一些数据。这就是为什么推动视图控制器需要 3_4 秒,而您认为 didSelectRowAtIndexPath 选择单元需要一些时间。
-
单元格高亮怎么样?它是立即发生还是仅在延迟之后发生?周围有任何活跃的 UIGestureRecognizer 吗?
标签: ios objective-c uitableview