在我的应用程序中,我有一个按编程方式执行segue的按钮:
- (void)myButtonMethod
{
//execute segue programmatically
[self performSegueWithIdentifier: @"MySegue" sender: self];
}
Run Code Online (Sandbox Code Playgroud)
我想知道是否有一种方法可以引用目标视图并传递一些参数.
我知道在prepareForSegue
方法中,我可以用:来引用它myDestinationViewController *vc = [segue destinationViewController];
,但我不知道如何以编程方式执行segue.
你有什么想法?
谢谢,亚萨
更新:
对不起这个问题我很抱歉!我只是发现,即使以编程prepareForSegue
方式调用segue,也会调用该方法,因此可以以相同的常规方式传递参数.
我正在寻找其他方法来以编程方式推送在故事板上实例化的视图控制器.我实际上找到了两种方法,我用它来进入下一个视图,但也回到上一个视图:
使用pushViewController
:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle: nil];
LocationWebView *lvc = [storyboard instantiateViewControllerWithIdentifier:@"LocationWebView"];
[self.navigationController pushViewController:lvc animated:YES];
Run Code Online (Sandbox Code Playgroud)以Segue
编程方式执行:
[self performSegueWithIdentifier: @"SongSegue" sender: self];
Run Code Online (Sandbox Code Playgroud)您是否有关于替代品的一些提示以及应该执行此操作的最佳方式?请注意,我不是指模态视图.
我在将应用程序委托的上下文传递给视图控制器时遇到了一些问题.我在互联网上找到了很多教程,并建议使用该didFinishLaunchingWithOptions
方法创建视图控制器,设置上下文属性并推送它.我的问题是我想使用storyboard,视图控制器是在其中创建和推送的,而不是在app delegate中.
我试图在我的app委托中执行此操作:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//instantiate local context
NSManagedObjectContext *context = [self managedObjectContext];
if (!context)
{
// Handle the error.
NSLog(@"Error: Context is null");
}
//reference the view controller
helloCoreDataViewController1_001 *rootViewController = [helloCoreDataViewController1_001 alloc];
// Pass the managed object context to the view controller
rootViewController.managedObjectContext = context;
return YES;
}
Run Code Online (Sandbox Code Playgroud)
这在我的视图控制器中:
@implementation helloCoreDataViewController1_001
@synthesize name, address, phone, status, managedObjectContext;
//....
- (IBAction)saveContact
{
NSLog(@"name: %@",self.name.text);
NSLog(@"address: %@",self.address.text);
NSLog(@"phone: %@",self.phone.text);
//Save the new instance of …
Run Code Online (Sandbox Code Playgroud) 我在实现选择列表时遇到了集成segue和协议的一些问题.
在我的选择列表中.h我有:
#import <UIKit/UIKit.h>
@protocol SelectionListViewControllerDelegate <NSObject>
@required
- (void)rowChosen:(NSInteger)row;
@end
@interface SelectColor : UITableViewController <NSFetchedResultsControllerDelegate>
-(IBAction)saveSelectedColor;
@property (nonatomic, strong) id <SelectionListViewControllerDelegate> delegate;
@end
Run Code Online (Sandbox Code Playgroud)
在我的选择列表中.我有:
@implementation SelectColori
@synthesize delegate;
//this method is called from a button on ui
-(IBAction)saveSelectedColore
{
[self.delegate rowChosen:[lastIndexPath row]];
[self.navigationController popViewControllerAnimated:YES];
}
Run Code Online (Sandbox Code Playgroud)
我想通过从另一个表视图执行segue来访问此选择列表视图:
@implementation TableList
...
- (void)selectNewColor
{
SelectColor *selectController = [[SelectColor alloc] init];
selectController.delegate = (id)self;
[self.navigationController pushViewController:selectController animated:YES];
//execute segue programmatically
//[self performSegueWithIdentifier: @"SelectColorSegue" sender: self];
}
- (void)rowChosen:(NSInteger)row
{
UIAlertView * errorAlert …
Run Code Online (Sandbox Code Playgroud) 故事板给我带来了很多问题!:(
现在我想在iOS中将图像作为tableview的背景.我在photoshop中做了一个透明的png图像,并将其导入到我的项目中.
**第一个问题是:是否可以在故事板中设置图像背景?我认为一个好主意是创建和图像视图并将其放在我的桌面视图上......但是故事板不允许我这样做.
**我也尝试通过代码添加背景图片:
- (void)viewDidLoad
{
[super viewDidLoad];
self.tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"table_background.png"]];
...
}
Run Code Online (Sandbox Code Playgroud)
即使png是透明的,我也用黑色背景而不是白色获得了可怕的结果!
此外,我已经读过,为了优化性能,应该更好地避免细胞的透明背景.
那么,将图像设置为带有故事板的表格视图的背景的最佳方法是什么?
谢谢,yassa
我已经实现了一个填充了核心数据的表格,现在我正在尝试通过显示侧面字母(以类似联系人的格式)对其进行索引.
在下面的代码中,如果我使用注释行,我只有现有部分的字母.但我想要整个字母表,所以我改变了返回的数组:
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
//return [fetchedResultsController sectionIndexTitles];
indexArray = [NSArray arrayWithObjects: @"{search}", @"A", @"B", @"C", @"D", @"E", @"F", @"G", @"H", @"I", @"J",@"K", @"L", @"M", @"N", @"O", @"P", @"Q", @"R", @"S", @"T", @"U", @"V", @"W", @"X", @"Y", @"Z", @"#", nil];
return indexArray;
}
Run Code Online (Sandbox Code Playgroud)
所有字母都显示在侧面索引上.但是现在我要实现返回所选部分索引的方法,这里我遇到了一些问题:
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
{
//return [fetchedResultsController sectionForSectionIndexTitle:title atIndex:index];
NSString *correspondingLetter = [indexArray objectAtIndex:index];
NSUInteger correspondingIndex = [[fetchedResultsController sections] indexOfObject:correspondingLetter];
NSLog(@"------index:%i\ncorrespondingLetter: %@\ncorrespondingIndex: %i\n", index,correspondingLetter, correspondingIndex);
return correspondingIndex;
}
Run Code Online (Sandbox Code Playgroud)
使用上面的代码,如果我使用注释行,每次选择没有相应部分的字母时都会出错.所以我想要做的是使用已选择的字母检索部分索引并将其位置搜索到现有部分.但它不起作用.你有什么想法?
谢谢,yassa
ios ×6
storyboard ×3
core-data ×2
segue ×2
alphabet ×1
background ×1
controller ×1
delegates ×1
image ×1
indexing ×1
parameters ×1
protocols ×1
push ×1
uitableview ×1
view ×1
views ×1
xcode ×1