ios - popToRootViewController 时 View 闪烁

标签 ios objective-c flash uitableview poptoviewcontroller

我在使用 popToRootViewController 时遇到问题。我有一个 Root View A 和一个 TableView B。当在 TableView 中选择一行时,我将一个字符串传递回 Root View 并取决于该字符串。我更改了 A 上按钮的标题。

我制作了一个非常简单的版本并将其放在 gitHub 上的链接:https://github.com/spennyf/didSelect_test .我这样做是因为很难解释,直到您真正在模拟器的手机上运行它。并看到闪光灯。我不知道为什么会发生或如何解决它。任何帮助将不胜感激 我还将在下面发布大部分代码,但是如果您可以自己看到闪光灯,我认为这将有助于解释问题。继承人的代码:

viewControllerA.h

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController

@property (strong, nonatomic) IBOutlet UIButton *btn1;

@property (strong, nonatomic) IBOutlet UIButton *btn2;

@property (strong, nonatomic) IBOutlet NSString *object;

@end

viewControllerA.m

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)viewWillAppear:(BOOL)animated {
    NSLog(@"object: %@", _object);
    if ([_object isEqualToString:@"object1"]) {
        [_btn1 setTitle:@"new1" forState:UIControlStateNormal];
    }
    if ([_object isEqualToString:@"object2"]) {

        [_btn2 setTitle:@"new2" forState:UIControlStateNormal];
    }

}

@end

tableviewB.m

#import "TableViewController.h"
#import "ViewController.h"

@interface TableViewController () {
    NSMutableArray *_objects;

}


@end

@implementation TableViewController


- (void)viewDidLoad
{
    [super viewDidLoad];

    _objects = [[NSMutableArray alloc] init];

    NSDictionary *obj1 = [[NSDictionary alloc] initWithObjectsAndKeys:@"object1", @"title", nil];
    NSDictionary *obj2 = [[NSDictionary alloc] initWithObjectsAndKeys:@"object2", @"title", nil];
    // NSDictionary *obj3 = [[NSDictionary alloc] initWithObjectsAndKeys:@"rpi", @"title", nil];

    [_objects addObject:obj1];
    [_objects addObject:obj2];



}



#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return _objects.count;

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";


    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }

    //NSLog(@"%@", _objects);
    cell.textLabel.text = [[_objects objectAtIndex:indexPath.row] objectForKey:@"title"];

    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    ViewController *myController = (ViewController *)[self.navigationController.viewControllers objectAtIndex:0];
    myController.object = [[_objects objectAtIndex:indexPath.row] objectForKey:@"title"];
    [self.navigationController popToRootViewControllerAnimated:YES];

}


@end

再次感谢您的帮助。

最佳答案

你的代码没有问题。当标题更改时,UIButtonTypeSystem 类型的 UIButton 的预期行为会闪烁。

一个简单的解决方法是将按钮的类型设置为 UIButtonTypeCustom

编辑: 您可以在 Interface Builder 中更改按钮的类型:

Changing the button type in Interface Builder

关于ios - popToRootViewController 时 View 闪烁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23922596/

相关文章:

c# - C#软件包Tyrrrz/YoutubeExplode对于YouTube html5视频返回错误403,但对于Flash视频则不返回错误403

ios - 未在自定义单元格标签内的 UIbutton 中执行操作

iOS Enterprise 分发错误 - "cannot connect to server"?

iphone - EXC_BAD_ACCESS(代码=2,地址=0x3)

javascript - 如何使用 JavaScript 检测浏览器中是否禁用了 Flash Player?

javascript - Flash AS2 - 动态文本打开新窗口并进行 JavaScript 调用

objective-c - 流式传输数据以响应 CFHTTPMessageRef 可能吗?

objective-c - iPhone本地是否有类似Xcode的输出日志?

c# - iPhone 编程 - 印象,意见?

iphone - 类的实现部分中的 void main 方法