创建UITableViewCell程序奔溃

来源:互联网 发布:网站主持人源码 编辑:程序博客网 时间:2024/09/21 06:33

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{    return 3;}- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{    static NSString * cellID=@"cellID";    UITableViewCell * cell=[tableView dequeueReusableCellWithIdentifier:cellID forIndexPath:indexPath];        if (!cell) {        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];    }    UIImageView * imgView=[cell viewWithTag:232];    if (imgView==nil) {        imgView=[[UIImageView alloc]initWithFrame:CGRectMake(screenSize.width-110, 10, 100, 60)];        [cell addSubview:imgView];    }    imgView.image=[UIImage imageNamed:@"sxd"];    cell.textLabel.text=@"哈哈";    return cell;}- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{    return 80;}


每次程序一运行就出错,看不出哪里不合适,报错

Assertion failure in -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit/UIKit-3512.60.7/UITableView.m:6573

觉得没什么不对啊这个方法,搜索之后发现把

UITableViewCell * cell=[tableView dequeueReusableCellWithIdentifier:cellID forIndexPath:indexPath];
改为<p style="margin-top: 0px; margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span style="font-variant-ligatures: no-common-ligatures;">UITableViewCell</span><span style="font-variant-ligatures: no-common-ligatures;"> * cell=[tableView </span><span style="font-variant-ligatures: no-common-ligatures;">dequeueReusableCellWithIdentifier</span><span style="font-variant-ligatures: no-common-ligatures;">:cellID];</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 175, 202);">就对啦,明天再追加两个方法的区别,虽然很低级的错误</p>

0 0
原创粉丝点击