小编yas*_*sin的帖子

以编程方式执行Segue并将参数传递到目标视图

在我的应用程序中,我有一个按编程方式执行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,也会调用该方法,因此可以以相同的常规方式传递参数.

parameters view storyboard ios segue

173
推荐指数
2
解决办法
17万
查看次数

以编程方式使用故事板推送视图控制器的其他方法

我正在寻找其他方法来以编程方式推送在故事板上实例化的视图控制器.我实际上找到了两种方法,我用它来进入下一个视图,但也回到上一个视图:

  1. 使用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)
  2. Segue编程方式执行:

    [self performSegueWithIdentifier: @"SongSegue" sender: self];
    
    Run Code Online (Sandbox Code Playgroud)

您是否有关于替代品的一些提示以及应该执行此操作的最佳方式?请注意,我不是指模态视图.

push views storyboard ios

57
推荐指数
2
解决办法
6万
查看次数

在iOS中传递上下文以将Core Data与Storyboard一起使用

我在将应用程序委托的上下文传递给视图控制器时遇到了一些问题.我在互联网上找到了很多教程,并建议使用该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)

xcode core-data ios managedobjectcontext

9
推荐指数
1
解决办法
5292
查看次数

正确访问segue的目标视图控制器以分配协议代理

我在实现选择列表时遇到了集成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)

delegates controller protocols ios segue

7
推荐指数
1
解决办法
6667
查看次数

在iOS中使用Storyboard将图像设置为TableView的背景

故事板给我带来了很多问题!:(

现在我想在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

background image storyboard uitableview ios

6
推荐指数
1
解决办法
7150
查看次数

核心数据中部分索引的整个字母表

我已经实现了一个填充了核心数据的表格,现在我正在尝试通过显示侧面字母(以类似联系人的格式)对其进行索引.

在下面的代码中,如果我使用注释行,我只有现有部分的字母.但我想要整个字母表,所以我改变了返回的数组:

- (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

indexing core-data alphabet ios

5
推荐指数
1
解决办法
2651
查看次数