【发布时间】:2013-08-14 14:26:20
【问题描述】:
SO 已经提出了类似的问题。我的情况略有不同,所以我将作为一个新问题发布。
我有一个 scrollView 作为控制器的主视图。它包含两个子视图:
- 以 UIView 作为子级的滚动视图。
- 包含一些数字文本字段的表格视图。
我已将UITapGestureRecognizer 附加到子滚动视图,以便用户可以从任何文本字段中关闭键盘。
UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tableTouched:)];
[topScrollview addGestureRecognizer:tap1];
tap1.delegate = self;
-(void) tableTouched:(UITapGestureRecognizer *)gesture
{
[portTable endEditing:YES];
portTable.scrollEnabled = YES;
}
-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:nil];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
}
cell.accessoryType = UITableViewCellAccessoryNone;
cell.textLabel.font = myFont;
cell.textLabel.textColor = [UIColor whiteColor];
switch (indexPath.row) {
case 0:
{
UILabel *tradeLabel = [[UILabel alloc] initWithFrame:CGRectMake(9, 5, 60, 40)];
tradeLabel.text = @"Trade";
tradeLabel.font = myFont;
tradeLabel.textColor = [ColorCodes sharedManager].orangeTextColor;
tradeLabel.backgroundColor = [UIColor clearColor];
[cell.contentView insertSubview:tradeLabel aboveSubview:cell.textLabel];
break;
}
//similar cases
}
return cell;
}
现在,如果我继续滚动 tableview 一段时间,我会因标题中提到的消息而崩溃。使用仪器的堆栈跟踪如下:
我无法理解我的控制器出现负引用计数的原因。我没有设置任何scrollview delegate,那为什么引用计数变成-1?
我已经尝试将手势附加到主滚动视图、tableview 本身和子 UIView,但仍然遇到同样的崩溃。请有人指出我正确的方向。谢谢。
编辑
我刚刚得到的另一个堆栈跟踪:
【问题讨论】:
-
将您的@propery 从
retain转换为strong -
放置cellForRowAtIndexPath方法的代码
-
我没有设置任何@property 来保留。都很强。顺便说一句,两者几乎相同。
-
@iPatel 我的
cellForRowAtIndexPath已经初始化了许多自定义控件。你确定要看看吗? -
把它写成.. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSString *CellIdentifier = [NSString stringWithFormat:@"S%1dR%1d" ,indexPath.section,indexPath.row]; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if(cell == nil) { cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; /// 把你的代码放在这里。 } /// 把你的代码放在这里。返回单元格; }
标签: ios uitableview uiviewcontroller uitapgesturerecognizer respondstoselector