获取UITableeViewCell的indexPath
创建单元格后如何获取单元格的索引路径?我需要设置一个uniq cell.tag。我还有什么其他想法可以做到这一点吗?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForManagedObject:(NSManagedObject *)managedObject
{
ConditionCell *cell = (ConditionCell *)[tableView dequeueReusableCellWithIdentifier:[ConditionCell reuseIdentifier]];
if ( nil == cell )
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"ConditionCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
} else
{
// Reset Image
cell.img.image = nil;
}
原因是我需要在不同的线程中找到单元格
[condition processImageDataWithBlock:^(NSData *imageData) {
if (self.view.window) {
if (cell.tag == [self.tableView indexPathForCell:cell].row)
{
NSLog(@"%@",cell.tag);
UIImage *image = [UIImage imageWithData:imageData];
[condition writeToFile:imageData];
if (image)
{
cell.img.image = image;
[cell.activityIndicator stopAnimating];
[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:[self.tableView indexPathForCell:cell]] withRowAnimation:UITableViewRowAnimationNone];
}
[condition release];
}
}
}];
How can I get the cell's indexpath after I have created the cell? I need to set a uniq cell.tag. Any other idea how I can do that?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForManagedObject:(NSManagedObject *)managedObject
{
ConditionCell *cell = (ConditionCell *)[tableView dequeueReusableCellWithIdentifier:[ConditionCell reuseIdentifier]];
if ( nil == cell )
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"ConditionCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
} else
{
// Reset Image
cell.img.image = nil;
}
The reason is I need to find the cell in a different thred
[condition processImageDataWithBlock:^(NSData *imageData) {
if (self.view.window) {
if (cell.tag == [self.tableView indexPathForCell:cell].row)
{
NSLog(@"%@",cell.tag);
UIImage *image = [UIImage imageWithData:imageData];
[condition writeToFile:imageData];
if (image)
{
cell.img.image = image;
[cell.activityIndicator stopAnimating];
[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:[self.tableView indexPathForCell:cell]] withRowAnimation:UITableViewRowAnimationNone];
}
[condition release];
}
}
}];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许问题是你不在主线程上调用它,因为它是一个 UIView - 试试这个:
indexPath 在块中使用时将是一个副本,所以如果你希望初始化的值反映在块之外,请像这样声明它所以:
Perhaps the problem is your calling it not on the main thread because it is a UIView - try this:
indexPath will be a copy when used in the block, so if you want the value you initialized to be reflected outside of the block declare it like so: