TableView 使用时的一个异常

来源:互联网 发布:钟振振厉害吗 知乎 编辑:程序博客网 时间:2024/04/30 09:14
node是一个结构体,aNode作为node类型的指针,datalist是table的数据源,数据添加方法如下
[_dataList addObject:[NSValue value:&aNode withObjCType:@encode(struct node)]];


下面是tableView部分:
static BOOL isRegNib = NO;if (!isRegNib) {[tableView registerNib:[UINib nibWithNibName:@"nodeCell" bundle:nil] forCellReuseIdentifier:@"nodeCell"];isRegNib = YES;}nodeCell * cell =(nodeCell*)[tableView dequeueReusableCellWithIdentifier:@"nodeCell"];node *aNode;[[_dataList objectAtIndex:indexPath.row]getValue:&aNode];NSString *str=[NSString stringWithCString:aNode->value encoding:NSUTF8StringEncoding];[[cell textLabel]setText:str];


然后异常发生在最后行

[productListViewController textLabel]: unrecognized selector sent to instance

仔细检查发现cell的类型变成了productListViewController!!断点跟踪后发现cell类型改变是由于执行倒数第3句引起!!一个和cell没有半点关系的语句居然导致了cell属性的改变,这是我所不解的,猜测是指针引起,所以将改声明node aNode;之后cell返回是正常了但是str返回全成viewdidload。。。



0 0
原创粉丝点击