0
我是iOS應用程序開發的全新手。爲什麼不使用指針變量
我下面的教程,裏面有在BIDAppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.switchViewController = [[BIDSwitchViewController alloc]
initWithNibName:@"SwitchView" bundle:nil];
UIView *switchView = self.switchViewController.view;
/**** WHY here do not use pointer variable? ****/
CGRect switchViewFrame = switchView.frame;
switchViewFrame.origin.y+=[UIApplication sharedApplication].statusBarFrame.size.height;
switchView.frame = switchViewFrame;
self.window.rootViewController=self.switchViewController;
...
...
return YES;
}
我明白了什麼是上面的代碼下面的代碼片段做,通常,當應用程序啓動,它加載的觀點根控制器(switchViewController
)&進行一些視圖調整。
我的問題是,在代碼中爲什麼CGRect switchViewFrame = switchView.frame;
不像這樣使用指針變量:CGRect *switchViewFrame = switchView.frame;
?
===============更新==================
現在才知道的原因CGRect
是一個結構,而不是一個Objective-C類。 然後,我可以重新定義的代碼行:
struct CGRect switchViewFrame, *sViewFrame;
sViewFrame = switchView.frame;
是上面的代碼相同CGRect switchViewFrame = switchView.frame;
?
我可以重新定義一行代碼:struct CGRect switchViewFrame,* sViewFrame; sViewFrame = switchView.frame;'? – Mellon
你爲什麼要做這樣的事情? Objective-C是C的一個嚴格超集,你必須放心地混合C和Objective-C。 – PatrickNLT
您將不得不爲sViewFrame分配內存(並釋放它),並確保您複製數據內容,否則您必須將switchView.frame的地址分配給sViewFrame。但是,它不符合你的建議。你爲什麼想這麼做?或者你只是出於好奇 - 這是可以理解的和學習的問題? –