0
我已经在我的代码,访问NSUInteger产权一些问题,这看起来像:访问NSUInteger财产
MyController.h
@interface MyController : UIViewController
@property (retain, nonatomic) NSArray *updatesArray;
@property (nonatomic) NSUInteger madeUpdatesCounter;
@property (nonatomic) NSUInteger allUpdatesCounter;
@end
MyController.m
@implementation MyController
@synthesize updatesArray;
@synthesize madeUpdatesCounter;
@synthesize allUpdatesCounter;
- (void)viewDidLoad
{
....
madeUpdatesCounter = 0;
allUpdatesCounter = [updatesArray count];
....
// Register for progress notifications
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(makeProgressChange)
name:@"MadeOneUpdateNotification"
object:nil];
}
- (void)makeProgressChange
{
madeUpdatesCounter++;
NSLog(@"Update progress: %d/%d", madeUpdatesCounter, allUpdatesCounter);
}
@end
我通过添加NSOperationQueue来将我的更新作为NSInvocationOperation进行检索。在一个更新动作的结束我送通知:
[[NSNotificationCenter defaultCenter] postNotificationName:@"MadeOneUpdateNotification" object:nil];
上面的代码执行后,接收notifocation是仅执行一次,并且在记录我看到成才这样的:
更新的进展:1/3
当我改变行:
allUpdatesCounter = [updatesArray count];
到
allUpdatesCounter = 3;
然后一切工作正常,我看到日志: 更新进度:1/3 更新进度:2/3 更新进度:加载视图前3/3
可变updatedArray被初始化。以这种方式完成:
MyController *doUpdatesVC = [self.storyboard instantiateViewControllerWithIdentifier:@"MyController"];
doUpdatesVC.updatesArray = updatesArray;
[self presentViewController:doUpdatesVC animated:YES completion:nil];
你有什么意见或提示我在我的代码中做错了什么?
你分配/初始化updatesArray? –
是的,我做到了。我从我的示例中排除了这行代码到清除。 – Grzegorz
您确定您的视图在* updatesArray *被分配之前加载? –