モーダルビューからデルゲートに情報を送信しようとしています。しかし、私の代理人はフォロースルーしていないようで、nullになります。IBhttp://i.imgur.com/7oaxb.pngではこのように見えます。 ただし、モーダルビューの直前にあるnavigationControllerを削除して、ビューのボタンを使用すると機能します。 助けてください、私は5時間のように試しました...:/
modalViewControllerコードは次のとおりです。#import #import "Link.h"
@protocol modalViewDelegate <NSObject>
-(void)closeview;
-(void)saveLink:(Link *)link;
@end
@interface modelViewController : UIViewController
@property (weak, nonatomic) IBOutlet UITextField *titel;
@property (weak, nonatomic) IBOutlet UITextField *url;
@property (nonatomic, weak) id <modalViewDelegate> delegate;
- (IBAction)exitModal:(id)sender;
- (IBAction)saveLink:(id)sender;
@end
そしてM:
#import "modelViewController.h"
@interface modelViewController ()
@end
@implementation modelViewController
@synthesize titel;
@synthesize url, delegate;
- (IBAction)exitModal:(id)sender {
//[self.delegate closeview];
[self dismissModalViewControllerAnimated:YES];
}
- (IBAction)saveLink:(id)sender {
if (titel.text.length > 0 && url.text.length > 0) {
NSString *urlen = [NSString stringWithFormat:@"%@", url.text];
Link *linken = [[Link alloc] initWithURL:[NSURL URLWithString:urlen]];
linken.title = titel.text;
NSLog(@"%@", delegate); **//returns null when pressing button** it returns null if i put it in viewDidLoad to..
[self.delegate saveLink:linken];
[self dismissModalViewControllerAnimated:YES];
} else {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil message:@"warning" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil, nil];
[alertView show];
}
}
@end
MasterViewController .h(モーダルビューをプッシュします:
#import <UIKit/UIKit.h>
#import "modelViewController.h"
@class DetailViewController;
@interface MasterViewController : UITableViewController <modalViewDelegate>
....
そしてM
#import "MasterViewController.h"
#import "DetailViewController.h"
@implementation MasterViewController
@synthesize detailViewController = _detailViewController;
@synthesize links;
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"linkPush"]) {
// Skicka länken till detaljvyn
DetailViewController *detailVC = segue.destinationViewController;
detailVC.link = [self.links objectAtIndex:self.tableView.indexPathForSelectedRow.row];
NSLog(@"%@", detailVC);
}
//this is the modalview "pusher"
if ([segue.identifier isEqualToString:@"newLink"]) {
modelViewController *mvc = segue.destinationViewController;
mvc.delegate = self;
NSLog(@"%@", mvc.delegate);
}
}
- (void)closeview {
[self dismissModalViewControllerAnimated:YES];
//[self.tabBarController dismissModalViewControllerAnimated:YES];
}
-(void)saveLink:(Link *)link{
NSLog(@"hello");
[links insertObject:link atIndex:links.count]; //updates a Tableview and works fine if delegate is called
[self.tableView reloadData];
//[self dismissModalViewControllerAnimated:YES];
}