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 *被分配之前加載? –