小编Ton*_*ony的帖子

故事板:使用委托/协议方法解除Popover

我读过的东西,在这个虽然大多数似乎是在关于非故事板的做法,我以为我已经拼凑在一起位和理解了它.但是,以下代码不会导致我的popover被解雇.Popover中的dismissPopoverButtonPressed按钮执行但委托中的dismissPopover方法中的断点永远不会发生.非常感谢有人密切关注代码以发现错误.

谢谢

在下面,NewGameViewController包含一个UIButton.按此按钮会弹出Popover Segue并随后显示包含PopViewController UIView的弹出窗口.

NewGameViewController.h

#import "PopViewController.h"
@interface NewGameViewController: UIViewController <DismissPopoverDelegate>
{
    UIPopoverController *popover;
}
Run Code Online (Sandbox Code Playgroud)

NewGameViewController.m

@implementation NewGameViewController
-(void)prepareForSegue:(UIStoryboardPopoverSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:@"popoverSegue"])
    {
        popover = [(UIStoryboardPopoverSegue *)segue popoverController];
        // getting warning: Assigning to 'id<UIPopoverControllerDelegate>' from incompatible type 'NewGameViewController *const__strong'
        //popover.delegate = self;
    }
}

-(void)dismissPopover
{
    [popover dismissPopoverAnimated:YES];
}
Run Code Online (Sandbox Code Playgroud)

PopViewController.h

@protocol DismissPopoverDelegate <NSObject>
-(void) dismissPopover;
@end

@interface PopViewController: UIViewController
{
    __unsafe_unretained id<DismissPopoverDelegate> delegate;
}

@property (nonatomic, assign) id<DismissPopoverDelegate> delegate;
-(IBAction)dismissPopoverButtonPressed:(id)sender;
@end
Run Code Online (Sandbox Code Playgroud)

PopViewController.m

#import …
Run Code Online (Sandbox Code Playgroud)

xcode storyboard uibutton popover

11
推荐指数
1
解决办法
6775
查看次数

搜索UITableView时隐藏索引栏

我已经为我的表视图实现了搜索栏和索引功能.运作良好.但是,我注意到当我在搜索栏中单击时,索引仍然可用并单击它会导致不可预测的结果.而不是调试,我认为隐藏索引会更简单:)

我在别处发现了调用sectionIndexTitlesForSectionView和返回nil的引用.所以,当我点击搜索框时,searchBarTextDidBeginEditing我已经明确调用了[self sectionIndexTitlesForSectionView:[self tableView]].

结果是sectionIndexTitlesForSectionView调用并返回nil,但索引仍然存在.

任何想法/建议将不胜感激!托尼.

indexing xcode uisearchbar ios

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

用于触发drawRect以重绘视图的按钮

我有一个带有子视图的VC.在subview level我有一个按钮.我希望按钮导致视图更新.

IBAction代码是在VC.它目前所做的只是切换一个BOOL值.

回到子视图中drawRect:方法是相应地测试BOOL和更改视图的代码.

我的观察是,当按下按钮时,IBAction代码会运行,切换BOOL,但drawRect:方法不会被调用.

我尝试手动调用drawRect(不是很好的做法而且没有用).我尝试调用setNeedsDisplay,但这也没有用(无法弄清楚如何引用以编程方式创建的子视图).

建议欢迎.

IBAction代码很简单,但包括在下面:

- (IBAction)rotateWindowButtonWasPressed:(id)sender
{
    // just flip the boolean here. Need to make the code change in drawRect: in top2View.m
    if ([myGlobals gWinVertical])
        [myGlobals setGWinVertical:NO];
    else
        [myGlobals setGWinVertical:YES];
    // Hoping this would force a redraw, but bounds have to change...:(
    //_top2ViewOutlet.contentMode = UIViewContentModeRedraw;
}
Run Code Online (Sandbox Code Playgroud)

xcode drawrect ibaction ios setneedsdisplay

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