毕业论文开发语言企业开发JAVA技术.NET技术WEB开发Linux/Unix数据库技术Windows平台移动平台嵌入式论文范文英语论文
您现在的位置: 毕业论文 >> 移动平台 >> 正文

respondsToSelector]: message sent to deallocated

更新时间:2013-8-10:  来源:毕业论文

respondsToSelector]: message sent to deallocated

定制table view cell, 里面包含一个UILabel, 一个 UITextField,当鼠标点击textfield要准备输入的时候,程序就crash, 报告一下信息:[NSObject respondsToSelector]: message sent to deallocated.

code 大致如下:
定制的cell:
ComboCell.h

@interace ComboCell: UITableViewCell <UITextFieldDelegate>
{
UITextField * textField;
UILabel *name;
}
@property (strong, nonatomic) IBOutlet UITextField * textField;
@property (strong, nonatomic) IBOutlet UILabel * textField;
@end

ComboCell.m
...
-(BOOL) textFieldShouldReturn:(UITextField *) textField
{
 [textField resignFirstResponder];
return YES.
}
还有一个 comboCell.xib, 里面就是在 UITableViewCell里面添加le label and textField, 并且把textField的delegate设定为 combocell.

使用这个cell的文件里主要有下面的东东:

-(void)viewDidLoad

  [super  viewDidLoad];
  
[self.tableview registerNib:[UINibnibWithNibName:@ComboCell"bundle"nil]forCellResuseIdentifier:@ComboCellId"];

...


-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath *) indexPath
{
   static NSString * cellID = @"ComboCellId";
ComboCell * cell = (ComboCell *)[tableView dequeueReusableCellWithIdentifier:cellId forIndexPath:indexpath];
return cell;
}

我注意到的一个现象是:如果我不把textField的delegate设定为 ComboCell, 就不会出现crash的现象, 似乎也跟我用nib来创建table cell 有关。 

希望高手指点是什么原因导致crash,怎样fix ? 我有很多不同的cell需要定制,我不想把textField的delegate指定为tableview 的controller.想让每一个模块都相对独立。
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath *) indexPath
{
   static NSString * cellID = @"ComboCellId";
ComboCell * cell = (ComboCell *)[tableView dequeueReusableCellWithIdentifier:cellId forIndexPath:indexpath];
if(cell == nil)
{
   cell = [ComboCell alloc] init......]; 方法自己视情况而定
}
return cell;
}

 其实在使用 nib来构造对象的时候,在ios6 里面已经不需要做  cell = nil 的判断了。仔细看  apple的文档就明白其中的原因了。我自己fix掉了这个问题。
在nib里面去掉textField的delegate的制定,
override  function awakeFromNib ()
在这里指定 textField的delegate.

{
 textField.delegate = self;
}

设为首页 | 联系站长 | 友情链接 | 网站地图 |

copyright©chuibin.com 优尔论文网 严禁转载
如果本毕业论文网损害了您的利益或者侵犯了您的权利,请及时联系,我们一定会及时改正。