草庐IT

self-register

全部标签

ios - @property 在幕后实际上做了什么......使用 self.和 self-> 和 _ 下划线

我仍在为@implementation部分的语法错误而苦苦挣扎。所以,我想了解使用和不使用@property之间的区别。第一种情况是一个@interface,我在{}中声明了一些变量。//ViewController.h#import#import"Student.h"//justclassimade@interfaceViewController:UIViewController{Student*stObj;}而且,我正在尝试使用多个标识符(_(下划线)、self.、self->、无)来引用stObj指针//ViewController.m#import"ViewController

ios - 为什么 self.navigationController pushViewController 不起作用?

我有一个UIViewController->UINavigationBar+UITableView再解释一下我通过UIBuilder做到了..1:使用XIB文件创建了一个新的UIViewController2:使用UIBuiler我放了一个UINavigationController3:然后我将UITableView放在navigationBar下面所以它给了我..A:UIViewController->UINavigationBar+UITableView现在我正在从工作正常的Web服务中将数据加载到UITableView中。我再次使用sam配置创建了一个xibB:UIViewCon

ios - "if (self = [super initWithFrame:frame reuseIdentifier:reuseIdentifier]) "有什么意义

想知道以下代码中if(self=[super...的意义是什么?它试图防止什么情况发生?-(id)initWithFrame:(CGRect)framereuseIdentifier:(NSString*)reuseIdentifier{if(self=[superinitWithFrame:framereuseIdentifier:reuseIdentifier]){//STUFFCONFIGUREDHERE}returnself;}采取fromhere. 最佳答案 它防止super实现返回nil。如果父类(superclass)

iphone - 什么时候按钮(UIButton)的目标不是 "self"?

我是iOS的初学者,在编程教程中以编程方式添加按钮时,目标始终设置为self,并且在创建它的Controller中,编写了一个Action(IBAction).或者通过界面生成器,将目标设置为文件所有者。我的问题是在什么情况下(一个例子会很好)目标不是自己。我能想到的一个场景是,在类(不是ViewController)方法中,根据条件创建按钮,因为该类不是ViewController,当初始化该类的对象时,将设置对当前ViewController的引用,如果按钮出现,它将用作为按钮定义操作的目标。 最佳答案 您可以将选择器指向任何目

ios - 为什么 self.splitViewController == nil?

我使用Xcode6的MasterDetailApplication模板创建了一个新的iOS8项目。我没有以任何方式更改代码。如以下屏幕截图所示,在DetailViewController.m中设置断点并检查self.splitViewController属性时,它返回nil。这是为什么?根据AppleUISplitViewControllerDocumentation,self.splitViewController应该返回最近的SplitViewController:Ifthereceiveroroneofitsancestorsisachildofasplitviewcontrol

iOS - GCD 对 self 的弱引用和强引用

当我在GCD的一个block中时,我总是使用__weak对self的引用。每个人都建议这样做。我知道在GCD中对self(tested)的强引用不会产生保留周期。Apple建议使用__weak对self的引用,然后使用__strong对_week的引用以保证self在block执行时不会是nil。我有以下代码:-(IBAction)startGCD:(id)sender{GCDVC*__weakweakSelf=self;[self.activityIndicatorstartAnimating];dispatch_async(dispatch_get_global_queue(DIS

ios - 设置 self.delegate = self 是不是糟糕的设计

我有一个UIViewController子类(比如MyViewController)。MyViewController.h@protocolTargetChangedDelegate-(void)targetChanged;@end@interfaceMyViewController@property(weak)idtargetChangedDelegate;-(void)doSomethingOnYourOwn;@endMyViewController.m@implementationMyViewController-(void)doSomethingOnYourOwn{//DOso

iphone - 在 iOS 上,如果 View Controller 还没有 View ,为什么 NSLog( @"self.view is %p", self.view) 会崩溃?

如果在Xcode4.3.2和AppDelegate.m中使用EmptyApp模板创建新的iOS项目:self.window.rootViewController=[[FooViewControlleralloc]init];在FooViewController的viewDidLoad中,如下:NSLog(@"self.viewis%p",self.view);NSLog(@"self.viewis%@",self.view);将打印出View,因此看起来默认的loadView将实例化一个View并将其分配给self.view。因此,如果我用一个全空的方法覆盖loadView,并注释掉上

ios - 为什么设备旋转时 self.view.frame 和 self.view.bounds 不同?

我想在设备旋转时更改一些布局。所以我实现了-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientationduration:(NSTimeInterval)duration方法来完成这项工作。但是我意识到当这个方法被调用时self.view.frame和self.view.bounds是不同的。self.view.bounds.size是正确的,self.view.frame.size似乎仍然没有旋转。例如,我创建了一个空的singleViewProject,实

objective-c - Objective-C中调用指定初始化器后如何进行附加初始化? ( self = [ self ...)

假设我有一个指定的初始化程序,它会像这样进行一些初始化:-(id)initWithBlah:(NSString*)arg1otherBlah:(NSArray*)arg2{if(self=[superinit]){...}returnself;}我有另一个初始化器需要调用它,然后执行一些其他设置任务:-(id)initWithSomeOtherBlah:(void*)creativeArg{//Isthisright?Itseemstocompileandrunasexpected,butfeelswrongself=[selfinitWithBlah:nilotherBlah:nil