Tag: 代表

IOS:tableview委托方法为两个tableview

我有一个类的tableview中的这些委托方法: – (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } – (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [array1 count]; } – (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if(cell == nil){ cell = [[[UITableViewCell alloc]initWithStyle:UITableViewStylePlain reuseIdentifier:CellIdentifier] autorelease] ; } cell.textLabel.text = [array1 objectAtIndex:indexPath.row]; return cell; } 如果我有一个单一的UITableView它没关系,但如果我有两个UITableView? 我如何组织我的代码? […]

prepareForSegue和代表

我有两个赛段的应用程序。 在其中一个segues中,当前的视图控制器成为代表,而另一个则不成立。 – (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if ([segue.identifier isEqualToString:@"MoreOptions"]) { UINavigationController *navigationController = segue.destinationViewController; MoreOptionsViewController *controller = (MoreOptionsViewController *)navigationController.topViewController; controller.delegate = self; } else if ([segue.identifier isEqualToString:@"FullStoryView"]) { SingleStoryViewController *detailViewController = segue.destinationViewController; detailViewController.urlObject = sender; } } 所有这一切工作正常,但我想尝试和更好地理解代码。 我不明白的是,我必须通过从navigationController.topViewController抓取它而不是简单地从segue.destinationViewController像我在第二条件如果条件获取引用的MoreOptionsViewController。 是因为我设置当前的视图控制器(自我)作为委托? 再次,我不是在试图解决问题,只是为了更好地理解发生的事情。

没有实现的委托方法导致崩溃

我创build了一个协议,并将其分配给一个委托对象 @protocol AppBrainDelegate <NSObject> @optional – (void)didLocateUser; – (void)didFinishLoadingDataWithData:(NSDictionary *)fetchedData; @end @interface Brain : NSObject @property (strong, nonatomic) id <AppBrainDelegate> delegate; 我认为这个@optional在协议声明中的含义是指控制器不需要监听委托方法,如果他们不想。 如果不在控制器中实现第一个委托方法,这里是崩溃日志。 如果我这样做,我不会崩溃。 似乎我不明白宣布委托方法为可选的概念。 你能向我解释我的错误在哪里吗? *终止应用程序由于未捕获的exception“NSInvalidArgumentException”,原因:' – [EventViewController didLocateUser]:无法识别的select发送到实例0x1fb300'

把委托方法放到一个类别中

我到现在为止开发了一些应用程序。 现在我正在写一个新的,在这个项目中我想保持代码非常干净,所以很容易find方法。 我想从UIViewControllers开始,它的视图有一个UITableView作为子视图。 我希望有一个名为DetailViewController的文件,用于直接属于它的所有function。 另一个名为DetailViewController+Protocols文件应该包含上面类的一个类和UITableView的所有这些委托方法。 有没有可能做这样的事情? 我想保持我的代码干净,并将其分割成多个文件。 编辑 DetailViewController.h @interface DetailViewController : UIViewController … Some Properties … Some Methods @end DetailViewController.m #import "DetailViewController.h" @implementation DetailViewController … Some Synthesizes … Some Methods @end DetailViewController + Protocols.h @interface DetailViewController (Protocols) <UITableViewDelegate, UITableViewDataSource> @end DetailViewController + Protocols.m @implementation DetailViewController (Protocols) – (NSINteger)numberOfSections { return …; } – (NSInteger)numberOfRowsInSection:(NSInteger)section […]

目标C代表声明

有人能告诉我之间的区别吗? @property (nonatomic, weak) id delegate; @property (nonatomic, weak) id <protocol_name> delegate; @property (nonatomic, weak) UIViewController * <protocol_name> delegate;

用Swift实现UITextFieldDelegate

我有我的ViewController类实现UITextFieldDelegate。 我没有自动完成的func,如textFieldShouldBeginEditing。 这是XCode 6中的错误吗? 这是我的类实现。 class ViewController: UIViewController, UITextFieldDelegate

animationDidStop方法的多个CAAnimations?

我知道你必须使用这个方法来获取animation完成时的委托方法: – (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag { 问题是,我将如何区分多个CAAnimations像2或更多? 我GOOGLE了这一点,我没有发现任何有用的东西。 请与我分享你是如何做到的! 谢谢!

如何更改uitableview删除button的文字

您好那里我试图改变显示在删除button时,用户在我的tableview中的一个uitableviewcell滑动的文本。 我在另一个问题线程中看到了一个例子,说使用这个tableview委托 – (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath 我的问题是,我如何使用这种方法..我不知道如何使用这个。

如何使用应用程序委托中的视图控制器的function?

我有一个通过蓝牙连接到设备的应用程序。 我希望应用程序发送一个命令,指示应用程序将在应用程序委托方法中closures:(void)applicationWillTerminate:(UIApplication *)application {

目标c – 使用委托传回string值

我想通过委托在ViewController中将UITextField * nameText从GreenViewController传递给UILabel * nameValue。 我做了委托,在ViewController中的onSave方法被调用,但屏幕不回去,名称不传递。 问题是什么? 这是标题和impelentation文件: GreenViewController.h #import <UIKit/UIKit.h> @protocol GreenViewDelegate <NSObject> -(void)onSave:(NSString*)nameValue; @end @interface GreenViewController : UIViewController @property id<GreenViewDelegate> delegate; @property (nonatomic) NSString* sliderValuePassed; @property (weak, nonatomic) IBOutlet UIButton *Next; @property (weak, nonatomic) IBOutlet UIButton *Save; @property (weak, nonatomic) IBOutlet UIButton *Back; @property (weak, nonatomic) IBOutlet UILabel *sliderTextValue; @property (weak, nonatomic) IBOutlet […]