首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我无法使用indexpath方法在didselectrowwith索引为0的表格单元格中获取标签的值

我无法使用indexpath方法在didselectrowwith索引为0的表格单元格中获取标签的值
EN

Stack Overflow用户
提问于 2011-02-24 21:19:39
回答 1查看 523关注 0票数 0

我在下面的委托方法中设置标签的值

代码语言:javascript
复制
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

我也可以在表视图中看到这个值,但是当我尝试在表视图的didselect方法中获取该值时,我得到的结果是null,这也只是第0行。

请帮帮忙。

代码语言:javascript
复制
 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    AMDEL_DCV.showmap=FALSE;
    AMDEL_DCV.indexno=indexPath.row;

    UITableViewCell *cell1=[tableView cellForRowAtIndexPath:indexPath];
    UILabel *lbltemp=(UILabel *)[cell1 viewWithTag:indexPath.row];
        //AMDEL_DCV.distanceval is global in app delegate 
    AMDEL_DCV.distanceval=lbltemp.text; 
    NSLog(@"Label Text %@ and lbltemp teg%d",[NSString stringWithFormat:@"%@",lbltemp.text],lbltemp.tag);

    //[[NSNotificationCenter defaultCenter] removeObserver:self];   
    LocationsMap *LM1catView=[[LocationsMap alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];

    CATransition *animation = [CATransition animation];
    [animation setDuration:0.5];
    animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
    [animation setType:kCATransitionPush]; 
    [animation setSubtype:kCATransitionFromRight];  
    [[self.superview layer] addAnimation:animation forKey:nil];

    [self.superview addSubview:LM1catView];
    [LM1catView release];
    [self removeFromSuperview];
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-02-25 07:10:56

我的猜测是你实际上没有得到一个指向你的UILabel的指针,而不是你的UILabel的文本是空的。-[UIView viewWithTag:]将只返回其tag属性设置为您所要求的值的子视图。由于UITableViewCells的重用方式,在at UITableView的每个单元格中为同一个标签设置不同的标签可能不是一个好主意。您可能会更幸运地使用cell1.textLabel

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5105194

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档