-1

我创建了一个自定义 UITableViewCell 并在 Cell 上添加了一个 UIProgressView,因为当我在 UITableView 上添加一行时,我从 XML 数据下载信息,并且我想使用 ProgressView 来显示进程的进度,我的问题是,如何检测我必须在哪个索引行中更改进度条,然后将其隐藏?...刚刚创建的行的索引路径是什么?

在里面:

cellForRowAtIndexPath:(NSIndexPath *)indexPath

我以这种方式从我的自定义 UITableViewCell 中检索信息:

UILabel *label;

label = (UILabel *)[cell viewWithTag:1000];
label.text = [[managedObject valueForKey:@"firstName"] description];

那么我如何知道刚刚添加的行的索引路径行,然后更改进度条?

4

1 回答 1

0

我想我不明白你在问什么。indexPath 是您刚刚创建的行的 IndexPath。您将属性设置为此值,但该属性将仅包含创建的最后一行的 IndexPath。

更新以显示示例:

方法 1 - 您没有从 cellForRowAtIndexPath 中调用其他方法。在这种情况下,您将需要一个 NSIndexPath 类型的私有属性(仅包含 MyViewController 导入和 @interface 声明的代码,以向您展示在何处放置私有属性声明:

在您的 .m 文件中:

#import "MyViewController.h" 

@interface MyViewController ()
    @property(nonatomic,strong) NSIndexPath *lastIndexPathCreated;
@end

@implementation MyViewController
@synthesize lastIndexPathCreated;

...

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// All your other cell setup code

self.lastIndexPathCreated = indexPath;
return cell;
}

-(void)someOtherMethod {
    // The last IndexPath of the row LAST created is self.lastIndexPathCreated
}

方法 2:假设您从 cellForRowAtIndexPath 中调用其他方法:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    // All your other cell setup code
    [self myOtherMethodWithIndexPath:indexPath];
    return cell;
}

-(void)myOtherMethodWithIndexPath:(NSIndexPath *)lastIndexPath {
    // Do something with lastIndexPath
}

希望这可以帮助

于 2012-03-25T23:23:28.563 回答