我在下面的委托方法中设置标签的值
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath我也可以在表视图中看到这个值,但是当我尝试在表视图的didselect方法中获取该值时,我得到的结果是null,这也只是第0行。
请帮帮忙。
- (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];
}发布于 2011-02-25 07:10:56
我的猜测是你实际上没有得到一个指向你的UILabel的指针,而不是你的UILabel的文本是空的。-[UIView viewWithTag:]将只返回其tag属性设置为您所要求的值的子视图。由于UITableViewCells的重用方式,在at UITableView的每个单元格中为同一个标签设置不同的标签可能不是一个好主意。您可能会更幸运地使用cell1.textLabel。
https://stackoverflow.com/questions/5105194
复制相似问题