我有一个故事板场景,它是一个UITabBarController场景,它有大约 5 个标签栏项目。我想要做的是根据用户的捆绑设置删除一两个项目。所以,我创建了一个UITabBarController .h和.m文件,如下所示:
.h:
#import <UIKit/UIKit.h>
@interface LHTabBarController : UITabBarController
@end
Run Code Online (Sandbox Code Playgroud)
.h:
#import <Foundation/Foundation.h>
#import "LHTabBarController.h"
@implementation LHTabBarController
-(void)viewDidLoad
{
/*NSMutableArray *tabbarViewControllers = [NSMutableArray arrayWithArray: [self.tabBarController viewControllers]];
[tabbarViewControllers removeObjectAtIndex:1];
[self.tabBarController setViewControllers: tabbarViewControllers];*/
[super viewDidLoad];
}
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[super viewDidAppear:animated];
}
-(void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
@end
Run Code Online (Sandbox Code Playgroud)
我将这个类连接到UITabBarController我的故事板中。
我尝试了注释掉的代码,但这给了我一个数组,说该数组为空。
如何从这个类中删除标签栏项目?
有没有一种方法UISearchController可以让我使用故事板UISearchBar?我有一个带有导航栏的故事板 UI,其中包含我的搜索栏。如果我能保持这种方式就好了,因为以编程方式设置布局真的很不方便。我知道旧的UISearchDisplayController可以故事板。有没有办法用 UISearchController 做类似的事情?
我有一个应用程序UITabbar,我想在Tabbar中设置图像但我无法在Tabbar中设置图像.而不是因为它是图像我得到色彩的图像形状,是否可以像在Tabbar中设置图像?.
我已尝试此代码但无法设置图像.
UITabBar *tabBar = self.tabBar;
UITabBarItem *targetTabBarItem = [[tabbar items] objectAtIndex:0]; // whichever tab-item
UIImage *selectedIcon = [UIImage imageNamed:@"name-of-selected-image.png"];
[targetTabBarItem setSelectedImage:selectedIcon];
Run Code Online (Sandbox Code Playgroud) 这是我的布局。
我还使用此视频作为如何实现 UIScrollView 的参考,因为这是我第一次。https://www.youtube.com/watch?v=VE6DQGy4iS8
我不允许使用 UIStackView 因为我们的目标是 iOS 8。
我现在遇到的两个明显问题是:
我正在使用带有 UIWebView 的 UIViewController。在此 UIWebView 中,用户必须登录,成功登录后,应将用户重定向回应用程序。但就我而言,它保留在 UIWebView 中并且不会将我重定向回应用程序。
我尝试在 API Delegate 中使用此代码:
func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
DispatchQueue.main.async {
if (url.scheme == "go-back"){
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let controller = storyboard.instantiateViewController(withIdentifier: "WebView") as! ViewController
self.window?.rootViewController!.present(controller, animated: true, completion: { () -> Void in
})
}
}
return true
}
Run Code Online (Sandbox Code Playgroud)
并创建了一个 URL 方案,但它不起作用。
我在导航标题栏中添加了几个标签和图像。这一切都很好。但我想用 a 覆盖所有内容UIButton,但我无法UIButton注册任何水龙头。
这是我的视图层次结构:
所有内容均启用用户交互,并且我已IBAction连接到按钮,如下所示:
@IBAction func tapProjectEdit(_ sender: UIButton) {
print("This never fires. :(")
}
Run Code Online (Sandbox Code Playgroud)
UIButton导航栏中不允许有 吗?还有其他方法可以解决这个问题吗?
我正在查看Pro Core Data示例,我想知道传递ManagedObjectContext的好方法是什么.在本书的示例中,我看到作者在AppDelegate中初始化ManagedObjectContext,然后他在MasterViewController中执行此操作
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.title = NSLocalizedString(@"League Manager", @"League Manager");
id delegate = [[UIApplication sharedApplication] delegate];
self.managedObjectContext = [delegate managedObjectContext];
}
return self;
}
Run Code Online (Sandbox Code Playgroud)
然后,当从表行选择中将新的ViewController压入堆栈时,这样做:
NSManagedObject *team = [[self fetchedResultsController] objectAtIndexPath:indexPath];
TeamViewController *teamViewController = [[TeamViewController alloc] initWithMasterController:self team:team];
[self presentModalViewController:teamViewController animated:YES];
Run Code Online (Sandbox Code Playgroud)
使用StoryBoards,我再也看不到那种类型的init方法了.我看到prepareForSegue主要用于,我在Beginning iOS 5 Development书中看到,作者会做这样的事情:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
UIViewController *destination = ((UINavigationController *)segue.destinationViewController).topViewController;
if ([destination respondsToSelector:@selector(setDelegate:)]) {
[destination setValue:self forKey:@"delegate"];
}
Run Code Online (Sandbox Code Playgroud)
我无法想出一个很好的方法来保持我的类解耦,并在我的viewControllers中引用managedObjectContext.我是否在我需要查看的所有视图控制器上设置了一个managedObjectContext?我是否按照第一个示例中的作者执行的操作并保留对具有引用的MasterViewController的引用,并将其传递给我的不同ViewControllers?我不确定这样的事情的"最佳实践"是什么.谢谢!
我正在使用IOS 5和Storyboard编码.我已经构建了一个应用程序,其中我有一个tableView连接到带有搜索栏的sqlite数据库.当我们触摸一行时,它会自动转到另一个名为"详细信息"的视图控制器.我需要将数据从我的表视图传递到详细信息视图控制器,例如将author.title传递给labelText.text字段.有任何想法吗?
编辑问题:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
// NSString *Title;
Details *dv = (Details*)segue.destinationViewController;
author.title = dv.labelText.text;
}
Run Code Online (Sandbox Code Playgroud)
部分代码:
//
// Details.m
// AuthorsApp
//
// Created by georges ouyoun on 7/17/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#import "Details.h"
#import "Author.h"
@interface Details ()
@end
@implementation Details
@synthesize labelText;
@synthesize selectedAuthors;
@synthesize author;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad …Run Code Online (Sandbox Code Playgroud) 我有一个UISplitViewController,主人有一个嵌入在UINavigationController中的UIViewController.工具栏按钮负责通过segue启动UIPopoverController.这种弹出控制器包装了一个UIViewController,它也嵌入在一个名为SettingsViewController的UINavigationController中.
我可以从UIStoryboardPopoverSegue获取指向UIPopoverController的指针:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(UITableViewCell *)sender
{
if ([segue.identifier isEqualToString:@"Settings"]) {
UIStoryboardPopoverSegue *popoverSegue = (UIStoryboardPopoverSegue*) segue;
SettingsViewController *settingsViewController = ... // TODO
settingsViewController.popoverController = popoverSegue.popoverController;
}
}
Run Code Online (Sandbox Code Playgroud)
但我找不到一种方法来获取内部SettingsViewController的引用.我不想使用通过类方法可访问的静态字段,这将是一个可怕的解决方法.
我错过了什么才能做到正确?
谢谢你的帮助!
我试图在iOS 8的UIStoryboard中使用swift创建自定义标签栏控制器(objective-c也没关系).所以,我计划使用这段代码.
let item0: UITabBarItem = UITabBarController().tabBar.items[0] as UITabBarItem
item0.setFinishedSelectedImage(selectedImage0, withFinishedUnselectedImage: unselectedImage0)
Run Code Online (Sandbox Code Playgroud)
但是,问题是setFinishedSelectedImage不再支持,我看到了这个错误.我该如何实施?
从iOS 7及更早版本开始不推荐使用的API在Swift中不可用
uistoryboard ×10
ios ×8
objective-c ×2
swift ×2
core-data ×1
ios8 ×1
iphone ×1
uibutton ×1
uikit ×1
uiscrollview ×1
uisearchbar ×1
uitabbar ×1
uitableview ×1
uiwebview ×1
xcode ×1