我有一个嵌入在标准视图控制器中的tableview。 tableview有一个工具栏,我想显示它。
目前,工具栏仍未显示。
我试过了:
如果我直接访问表而不是通过嵌入视图访问表,则工具栏存在(并正确显示)。嵌入视图的操作是否会删除工具栏?
如何在嵌入视图中显示tableviews工具栏?
编辑:新代码
ParentViewController.h
#import <UIKit/UIKit.h>
#import <MessageUI/MessageUI.h>
#import "childTable.h"
@interface ParentViewController : UIViewController <MFMailComposeViewControllerDelegate, UpdateParentProtocol>
@property (weak, nonatomic) IBOutlet UIBarButtonItem *emailButton;
@property (weak, nonatomic) NSString *buttonEnabled;
@property (weak, nonatomic) ChildTable *childTableVC;
@end
parentViewController.m
#import "ParentViewController.h"
@interface ParentViewController () <MFMailComposeViewControllerDelegate>
@end
@implementation ParentViewController
@synthesize emailButton;
@synthesize buttonEnabled;
@synthesize childTableVC;
- (void)viewDidLoad
{
[super viewDidLoad];
[self.childTableVC setDelegate:self];
}
-(void) isButtonEnabled:(NSString *)enabledX {
NSLog(@"isButtonEnabled");
enabledX = buttonEnabled;
if ([buttonEnabled isEqualToString:@"FALSE"])
{
emailButton.enabled = FALSE;
}
else
{
emailButton.enabled = TRUE;
}
}
childTable.h
#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
@protocol UpdateParentProtocol <NSObject>
@required
-(void) isButtonEnabled: (NSString *) enabledX;
@end
@interface childTable: UITableViewController {
id <UpdateParentProtocol> delegate;
}
//@property (weak, nonatomic) IBOutlet UIBarButtonItem *emailButton;
@property (strong, nonatomic) NSString *enabledX;
@property (strong, nonatomic) id <UpdateParentProtocol> delegate;
childTable.m
-(void) tableView:(UITableView *)tableView didEndEditingRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"TableEditingEnded");
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
self.myArray = [defaults mutableArrayValueForKey:@"favourite_views_key"];
if (myArray == 0) {
enabledX = @"FALSE";
NSLog(@"PASSEDFALSE");
[[self delegate] isButtonEnabled:enabledX]; }
else {
enabledX = @"TRUE";
NSLog(@"PASSEDTRUE");
[[self delegate] isButtonEnabled:enabledX]; }
}
当我运行代码时,我从TableEditingEnded和PASSEDTRUE中获取NSLog打印,但没有isButtonEnabled。这告诉我 - (void)isButtonEnabled :( NSString *)enabledX未被调用。你能说明为什么吗?
答案 0 :(得分:1)
以下是如何使用协议从子视图与父视图控制器进行通信
@protocol UpdateParentProtocol <NSObject>
-(void)doSomething1;
-(void)doSomething2;
@end
@interface ParentViewController : UIViewController<UpdateParentProtocol>
@end
@implementation ParentViewController
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
TableViewController *tableViewController = segue.destinationViewController;
tableViewController.delegate = self;
}
-(void)doSomething1
{
NSLog(@"doSomething1");
}
-(void)doSomething2
{
NSLog(@"doSomething2");
}
@end
----
#import "ParentViewController.h"
@interface TableViewController : UITableViewController
@property(strong, nonatomic) id<UpdateParentProtocol> delegate;
@end
@implementation TableViewController
-(void)updateParentWithData
{
if( [self.delegate respondsToSelector:@selector(doSomething1)])
{
[self.delegate performSelector:@selector(doSomething1)];
}
}