Tag: 代表

重构iOS7和iOS8的UITableView委托

作为这个问题的后续行动: 在iOS中跳过/忽略方法 ,我试图在iOS7和iOS8中为我的UITableView实现单独的委托。 所以,作为第一步,在MyTableViewController viewDidLoad中,我添加了下面的代码: if ([[[UIDevice currentDevice] systemVersion] compare: @"8.0" options: NSNumericSearch] != NSOrderedAscending) { [self.tableView setDelegate: [[MyTVDelegate alloc] initWithIdentifier: myTVCellIdentifier]]; } else { [self.tableView setDelegate: [[MyTVDelegate7 alloc] initWithIdentifier: myTVCellIdentifier]]; } 我添加一个标识符,因为我将不得不将这个应用到多个视图控制器(或者我可能只是为每个电视创build一个委托类,我还没有想出来)。 我正在使用CoreData ,所以我的dataSource是一个NSFetchedResultsController 。 然后,我有以下MyTVDelegate/myTVDelegate7 : #import "MyTVDelegate.h" @implementation MyTVDelegate – (instancetype)initWithIdentifier: (NSString *) identifier { if ([super init]) { self.identifier = identifier; […]

如何委托工作和委托工作stream程在Objective-C

我是Objective-C的新手。 我正在学习Objective-C。 你会不会让我知道这个代码是如何工作的,以及你是否会帮助理解委托人在Objective-C中的工作stream程 SampleProtocol.h #import <Foundation/Foundation.h> @protocol SampleProtocolDelegate <NSObject> @required – (void) processCompleted; @end @interface SampleProtocol : NSObject { id <SampleProtocolDelegate> _delegate; } @property (nonatomic,strong) id delegate; -(void)startSampleProcess; @end 我在下面的代码中添加SampleProtocol.m后 #import "SampleProtocol.h" @implementation SampleProtocol -(void)startSampleProcess{ [NSTimer scheduledTimerWithTimeInterval:3.0 target:self.delegate selector:@selector(processCompleted) userInfo:nil repeats:NO]; } @end 为标签创build一个IBOutlet并将其命名为myLabel,并按照以下方式更新代码以在ViewController.h采用SampleProtocolDelegate #import <UIKit/UIKit.h> #import "SampleProtocol.h" @interface ViewController : UIViewController<SampleProtocolDelegate> { IBOutlet UILabel […]

添加到以前保存的NSUserDefaults

我正在为iOSdevise一款游戏,其中包括每个级别的评分系统。 在这里我有一些代码,通过使用委托获取NSString ( passedValue1 )。 下面是代表的代码: LevelCompleteLevel1 。H #import "ViewController.h" @interface LevelCompleteLevel1 : UIViewController{ IBOutlet UILabel *label; ViewController *secondviewData; } @property (nonatomic, retain)ViewController*secondviewData; .M ViewController *second = [[ViewController alloc] initWithNibName:nil bundle:nil]; self.secondviewData = second; secondviewData.passedValue1 = label.text; [self presentModalViewController:second animated:YES]; 在.m我发送一个值从当前view controller的标签到另一个view controller我发送的值被称为passedValue1值1 一旦我发送了我需要显示并保存在ViewController ViewController 。H @interface ViewController : UIViewController{ IBOutlet UILabel *label; NSString *passedValue1; […]

调用协议方法两次,Swift

我有从UITextFieldDelegate协议使用方法的子类文件 class MyTextField: UITextField, UITextFieldDelegate { . . . override func willMoveToSuperview(newSuperview: UIView?) { super.willMoveToSuperview(newSuperview) self.delegate = self } func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool { // some actions return true } } 在我的ViewController类中,我使用input字段与我的子类 class ViewController: UIViewController, UITextFieldDelegate { @IBOutlet weak var field: MyTextFieldMask! override func viewDidLoad() { super.viewDidLoad() // […]

如何使用委托从一个视图控制器传递消息到另一个使用委托?

主要故事板图像我有一个名为“Contacttableviewcontroller”的表视图控制器和一个视图控制器为“Detailviewcontroller”。 我有2个文本字段在我的视图控制器给联系人姓名和号码。 我有一个button来保存。 当我点击那个button时,它应该显示在Table View Controller中。 我正在使用的概念是使用委托从目的地到源代码传递信息。 这里是我的代码不正常工作。 Detailviewcontroller.h @protocol detailviewcontrollerdelegate<NSObject> – (void)additem:(NSString *)Name MOBILE:(NSString *)Mobile; @end @interface DetaiViewController : UIViewController @property (weak, nonatomic) IBOutlet UITextField *nametextfield; @property (weak, nonatomic) IBOutlet UITextField *mobiletextfield; – (IBAction)Save:(id)sender; @property(nonatomic,weak)id<detailviewcontrollerdelegate>delegate; Detailviewcontroller.m – (IBAction)Save:(id)sender { [self.delegate additem:self.nametextfield.text MOBILE:self.mobiletextfield.text]; } Contacttableviewcontroller.h @interface ContactTableViewController : UITableViewController<detailviewcontrollerdelegate> @property(strong,nonatomic)NSString *contactname; @property(strong,nonatomic)NSString *contactno; -(void)reloadtabledata; @property(strong,nonatomic)NSArray […]

NSURLConnection不会跨多个视图调用完成

今天早些时候,我问了以下问题: 推送视图时,iOS块被阻止 我提到的操作(OP1)实际上是使用NSURLConnection到我的服务器的“http get”。 经过更多调查,我发现这个街区并没有真正的“死亡”。 真正发生的是,即使在推送视图(通过[NSThread sleep:10]validation)之后,请求实际上是SENT(服务器端logging它)。 服务器响应,但没有任何事情发生在应用程序端,如果view2已被推动! 就好像连接失去了代表一样! 我看到的另一个可能性是“NSURLConnection与rsMainLoop相关的事实? 谁能帮忙? 请不要忘记: 0.只要视图2没有被推到操作完成,一切都可以正常工作。 1.请求被发送asynchronous 2.我设置委托,只要视图不改变,它就会工作 3.视图1使用“单独对象引用”属性“OP1Completed”开始操作 4.视图2通过“单体对象引用”上的属性检查OP1的完成情况, 5.视图2通过转到“singleton.OP1Result”属性获取“结果” 编辑1: 好吧,让我们有一些代码。 首先这里是我的单身人士(名为“交互”)的相关代码: -(void)loadAllContextsForUser:(NSString *)username{ userNameAux = username; _loadingContextsCompleted = NO; if (contextsLoaderQueue == NULL) { contextsLoaderQueue = dispatch_queue_create("contextsLoaderQueue", NULL); } dispatch_async(contextsLoaderQueue, ^{ NSLog(@"Loading all contexts block started"); [self requestConnectivity]; dispatch_async(dispatch_get_main_queue(), ^{ [Util Get:[NSString stringWithFormat:@"%@/userContext?username=%@", Util.azureBaseUrl, [username […]

警告:尝试使用SLComposeViewController将不在窗口层次结构中的*视为*

当我在游戏中推送Twitter图像时,我想显示共享图像(SLComposeViewController的模式显示)。 但是,当我推动Twitterbutton,显示不显示和日志说像标题。 然后,我search了类似的问题,但我不知道该怎么做… [ViewDidLoad]和[ViewDidAppear]是重要的事情,我知道。 以下是我的代码。 ViewController.m #import "ViewController.h" #import "NewGameScene.h" #import <Social/Social.h> #import "GameOverScene.h" @interface ViewController () { GameOverScene *gameOver; } @end @implementation ViewController //Loads the view onto our main class – (void)loadView { self.view = [[SKView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]]; } //Executes when view finishes loading – (void)viewWillLayoutSubviews { //extracted important code. [super viewDidLoad]; […]

如何在实现文件的委托中调用所需的方法

我有两个视图控制器VC1和VC2。 我通过prepareForSegue方法将值从VC1传递给VC2。 当我在VC2中收到这个值时,我将它乘以10.然后,在VC2中乘以10后,我想返回到VC1。 为了解决这个问题,我会使用Delegate 。 所以,我创build了DelegateDataProcessor类 但是我不知道如何在方法startProcessingValue调用processingDone完成所需的方法 请看下面的代码 ** DelegateDataProcessor.h **: #import <Foundation/Foundation.h> @protocol ProtocolDataProcessor <NSObject> @required – (void) processingDone; @end @interface DelegateDataProcessor : NSObject{ id <ProtocolDataProcessor> _delegate; } @property (nonatomic, strong) id delegate; -(void) startProcessingValue: (NSInteger) valueToBeProcessed; @end ** DelegateDataProcessor.m **: #import "DelegateDataProcessor.h" @implementation DelegateDataProcessor -(void) startProcessing:(NSInteger) value { value = value * 10; […]

方法被调用,但不能正确执行

我已经从CollectionViewController – > MenuTableViewController – > ListViewController成功链接链接的委托方法。 在ListViewController扩展中,我调用changeTitleView()但它不工作。 数据,但是成功通过,因为print(title)正确打印传递的信息。 如果在ListViewController调用, changeTitle()正确执行 class ListViewController { var navigationTitle: String? @objc func changeTitle(title: String) { let titleLabel = UILabel() let attributes: NSDictionary = [ NSAttributedStringKey.font:UIFont(name: "HelveticaNeue", size: 20)!, NSAttributedStringKey.foregroundColor: UIColor(red: 0.1137, green: 0.1137, blue: 0.149, alpha: 0.8) /* #1d1d26 */, NSAttributedStringKey.kern:CGFloat(2.0) ] let attributedTitle = NSAttributedString(string: title.uppercased(), attributes: […]

如何实施委托代替通知

## NetworkClass -(void)getResponse:(NSString *)url{ NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]]; [urlRequest setHTTPMethod:@"GET"]; NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration]; NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration]; NSURLSessionDataTask *task = [session dataTaskWithRequest: urlRequest completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { //check if we encountered an error if(error != nil){ NSLog(@"%@", [error localizedDescription]); }else{ //get and check the HTTP status code […]