Tag: 代表

内存pipe理与代表?

内存pipe理与委托,这是我的理解,我不保留委托,我有点不确定如何处理委托如果视图被卸载(通过viewDidUnload),后来重新创build(通过viewDidLoad)? @property(assign) SomeClass *someDelegate; 。 – (void)viewDidLoad { [super viewDidLoad]; someDelegate = [[SomeClass alloc] init]; [someDelegate setDelegate:self]; } -(void)viewDidUnload { [super viewDidUnload]; [self setSomeDelegate:nil]; } -(void)dealloc { [super dealloc]; } PS:我可能在错误的轨道上,我只是想把我的头转过来… 欢呼加里

在Swift上委托Objective-C协议

我使用Swift语言在iOS上实现UDP Listener。 为此,我在CocoaAsyncSocket项目上继续。 我成功地使用Bridging-Header.h导入CocoaAsyncSocket库,我可以从Objective-C类调用函数,但是我无法在swift上编写委托函数。 这是我设置Socket并将ViewController.swif定义为侦听器的委托类的代码: func setupSocket() { var udpSocket : GCDAsyncUdpSocket = GCDAsyncUdpSocket(delegate: self, delegateQueue: dispatch_get_main_queue()) var error : NSError? let port : UInt16 = 12121 let address : String = "228.5.12.12" udpSocket.bindToPort(port, error: &error) udpSocket.joinMulticastGroup(address, error: &error) udpSocket.enableBroadcast(true, error: &error) println("228.5.12.12") } 这是Objective-C中的前一个委托函数: – (void)udpSocket:(GCDAsyncUdpSocket *)sock didReceiveData:(NSData *)data fromAddress:(NSData *)address withFilterContext:(id)filterContext; 最后,这就是我在Swift上实现的function: override […]

从基类扩展委托

我有一个objc基类: @protocol BaseClassDelegate; @interface BaseClass : NSObject @property (nonatomic, weak) id <BaseClassDelegate> delegate; @end @protocol BaseClassDelegate <NSObject> -(void)baseDelegateMethod; @end 我正在创build一个快速的子类,我想扩展我的委托… protocol SubClassDelegate : BaseClassDelegate { func additionalSubClassDelegateMethod(); } class SubClass: BaseClass { @IBAction func onDoSomething(sender: AnyObject) { delegate?.additionalSubClassDelegateMethod(); <— No such method in 'delegate' } } 现在,当我创build我的子类,我可以说它符合SubClassDelegate并设置委托。 问题是(当然),这个子类中不存在“委托”。 有没有办法告诉编译器将我的委托“扩展”到我的子类中? (或者我在这里疯了,错过了一些明显的东西)

创build一个委托来从菜单中更改视图

我想能够从我的自定义菜单将视图控制器推到我的主子类导航控制器,我想要使用委托。 在我试图改变视图控制器之前,我去了一些更容易,改变当前的视图控制器标题。 这是迄今为止我写的代码,但在TableView单元上粘贴不会触发委托。 (或者看起来) 请指教 – > RootViewController / \ 容器容器 | | SlideMenuViewController SubClassed UINavigationController | | | | | UITableViewController VC1 VC2 VC3 VC4 SlideMenuViewController.h: @protocol SlidingMenuDelegate <NSObject> @end @interface SlideMenuViewController : UIViewController { id <SlidingMenuDelegate> delegate; } @property (strong, nonatomic) id delegate; SlideMenuViewController.m: – (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { //do something to […]

ViewDidLoad在AppDelegate didFinishLaunchingWithOptions执行之前运行!

我正在遇到一个奇怪的问题,方法“ViewDidLoad”运行之前,AppDelegate的didFinishLaunchingWithOptions执行! 原因我只检查数据库是否存在于“didFinishLaunchingWithOptions”我的应用程序崩溃,如果数据库不存在。 经过几个小时的讨论,我厌倦了这样做,并呼吁HEEEEELP! 如果你愿意,可以这么和善地指出我的方向是什么,我的项目可能是错的。 我不知道(aaarggh!) 谢谢! 最好的问候汤姆

iOS我可以把所有的委托方法放在另一个类上。 将代表inheritance到视图控制器

我想要的是将我所有的委托方法集中到一个类中。 在哪里我可以使用其默认值或覆盖委托方法。 例如: ViewController.m #import <UIKit/UIKit.h> @interface ViewController : UIViewController<UITableViewDataSource,UITableViewDelegate> @end ViewController.h #import "ViewController.h" #import "TableDelegateContainers.h" @interface ViewController () @end @implementation ViewController – (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. } TableDelegateContainers.h – (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return sample.count; } – (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ […]

点击像所有的视图应该显示如同C

当我selectThrowback – >如果我点击像button那样的描述发生像button改变不像和“像计数= 1099”增加。 如果我按回我希望这不像显示旁边显示在一个标签,并再次select回滚button应该显示不像和像计数应为1100.请帮助我如何实现这一目标? //DetailOfUser.m #impot"DetailsOfStories.h" @interface DetailOfUser ()<UITableViewDelegate,UITableViewDataSource> { NSMutableArray *arrayAboutList; DetailsOfStories *viewController; } – (UITableViewCell *)tableView:(UITableView *)theTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *cellIdentifier = @"cell"; UILabel *title=[(UILabel *)cell viewWithTag:2]; title.text=[NSString stringWithFormat:@"%@", [arrayAboutList[indexPath.row] valueForKey:@"title"]]; return cell; } -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ viewController=[self.storyboard instantiateViewControllerWithIdentifier:@"DetailsOfStories"]; viewController.descriptionList = [arrayAboutList[indexPath.row] mutableCopy]; [self.navigationController pushViewController:viewController animated:YES]; } @end //DetailsOfStories.m […]

Apple Push – didReceiveIncomingPushWithPayload未被调用 – 而是错误:发送消息失败到客户端

我有一个使用pushkit(voip推)的应用程序。 大部分时间推挤通过。 但是,当有很多的stream量,推动不通过应用程序。 我处于可以重现错误的状态。 我使用这里的扩展日志: https : //developer.apple.com/library/ios/technotes/tn2265/_index.html 我发现这个来检查日志logging: http : //iosdevelopertips.com/core-services/debug-failed-push-messages-by-logging-apsd-process.html 尽pipe如此,我还是遇到了两种不同的情况,在这种情况下,我只是没有进一步说明: – 在apsd-log中,我得到了 Received message for enabled topic … 在应用程序didReceiveIncomingPushWithPayload不会被调用。 我在函数的开始处生成一个日志条目,并且不做任何特殊的事情,这可能会阻止函数完成。 – 在我得到的apsd日志 Stream error occurred … 但没有find任何其他错误消息,为什么会发生此错误。 港口似乎没问题 重新启动应用程序后,推再次通过。 编辑: 日志文件中的相关错误似乎是: apsd[82]: Failed sending message to client: com.apple.telephonyutilities.callservicesdaemon.voip.push.development 似乎有两种types的情况:在某些情况下,可重复的stream量大,重新登记的推动,似乎有帮助。 在其他情况下,这是随机发生的,但事实并非如此。 重新启动应用程序也没有帮助。 所有帮助到目前为止,重新启动iPhone。 编辑: 我仍然在努力解决这个问题。 在某些情况下,我会在推送似乎失败之前收到内存警告。 在其他情况下,我得到这样的xpc通信警告: SpringBoard[43] <Warning>: Communications error: <OS_xpc_error: <error: […]

代表不在单身工作

为了通过多个视图build立networking连接,我创build了一个Singletonnetworking控制器来处理服务器和客户端之间的数据。 不幸的是,它不工作,因为委托方法不是从我的单身人士调用到另一个视图..在我的代码下面: **单例是SocketIOConnection.h和.m // // SocketIOConnection.h #import <Foundation/Foundation.h> #import "SocketIO.h" #import "SocketIOPacket.h" @protocol SocketIOConnectionDelegate <NSObject> @required – (void) receivedPacket:(id)packet; @end @interface SocketIOConnection : NSObject <SocketIODelegate> { SocketIO *IO; id <SocketIOConnectionDelegate> delegate; } @property (nonatomic, retain) IBOutlet SocketIO *IO; @property (retain) id <SocketIOConnectionDelegate> delegate; + (SocketIOConnection *)sharedSingleton; @end // // SocketIOConnection.m #import "SocketIOConnection.h" @implementation SocketIOConnection @synthesize […]

如何在表视图cusomization过程中调用“willDisplayFooterView”方法?

我想调用这些方法: – (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section NS_AVAILABLE_IOS(6_0); – (void)tableView:(UITableView *)tableView willDisplayFooterView:(UIView *)view forSection:(NSInteger)section NS_AVAILABLE_IOS(6_0); 但我不能! 根本没有反应。 我在模拟器iOS 6.0上testing – (void) tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section { DLog(@"0>>"); CGRect originalRect = view.frame; UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"shadow_top.png"]]; [imageView setFrame:CGRectMake(0.0f, originalRect.size.height – imageView.frame.size.height, imageView.frame.size.width, imageView.frame.size.height)]; [view addSubview:imageView]; } – (void) tableView:(UITableView *)tableView willDisplayFooterView:(UIView *)view […]