Uinavgation Everyday Small bug-interested friends can see

Source: Internet
Author: User

Uinavgation Daily Uinavgation
  • Today in a small demo, found a bug, very interesting, is that you constantly call the navigation - (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated; method, found in the constant click of a button to call this method, in the click Back to call this - (UIViewController *)popViewControllerAnimated:(BOOL)animated; method, which is in a quick multiple click return not only did not return, The controller is also added to the navigition several times.
  • Well, the black Apple recording a little defective, the brain to fill the screen it.

  • What is the problem, the code is not many, you can see, then the problem is where?

push//Trigger Click event [BTN addtarget:target action:action forcontrolevents:uicontroleventtouchupinside];//receive button click Processing-(void) Btnclick: (UIButton *) btn{    [Self.navigationcontroller Pushviewcontroller:[[etrecommendcontroller alloc] init] Animated:yes];} pop//Trigger Click Time [backbtn addtarget:self action: @selector (POP)//Accept Click event-(void) pop{    [self popviewcontrolleranimated : YES];}

  • Look at the current analysis.

    • I want to click Push to invoke the push method, return to call pop, and call it only once.
    • Now click on push is indeed displayed once, click on the pop, obviously see the addition of a lot of sub-controller in, and actually added a lot of self-control (in fact, indeed)
    • Here I am the custom navigation, then may be my custom inside the code inside writes the logic wrong, conflicts with the system, then changed the system the navigation, but the result is same.
    • I have to say that a detail is at the end of the button to return to this bug, in the middle point is all normal.
  • So I found the method call on the button push click event many times, but clearly see I have not returned to the root controller ah, but also see me click on the return button ah, suddenly I found that I call the push method of the[self.navigationController pushViewController:[[ETRecommendController alloc] init] animated:YES];Watch the back.animated:YESNavigation jump Drive painting effect, and this animation effect is through the coreanimation of the special animation to achieve, and the animation takes time, And in the runloop inside of the Nsdispalylink and Nstimer so if in a certain period of time does not complete the task will automatically skip, and now will not like this, after all, is based on the thread to run, and the threading architecture pattern is runloop, that is to say执行动画需要时间,在这个时间里面没有执行完动画,那么RunLoop直接处理下一个Source

  • Well, if that's the case, then just set the animation to No, then change yes to no, indeed, there is no problem, the problem seems to be solved, please pay attention to my above mentioned a detail.

  • 在按钮的两端点才回出现这个bug,在中间点则一切正常

  • If the effect of clicking on both ends is the same as in the middle, then the animation's Yes and no are persuasive, but it's obviously not.

  • And now it's such a situation.

      • When we click on the past, the push key (non-return key) animation effect, it becomes a situation: the middle of a module can not receive the corresponding, and around, that is, the middle and around is not the same block control, after all, according to the responder chain, looking for the most suitable view, so, If you can receive events then he must be the same view, unless he does not follow the responder chain, and now this is the situation, a control actually does not follow the responder chain, well, this conjecture is a little bold, the reason is more reluctant.

      • There is a need to popularize some of the details of Apple's knowledge, when we click on the iphone keyboard, for example, I clicked G, then the Apple will be from his system's own guessing dictionary to guess what we will press Next, it may be good, may be God, However, it is certain that the touch range of O is greater than the touch range of some letters, that is to say, although we seem to have not changed the keyboard, his every letter can receive the event's range is always dynamic change, this is the Apple user experience is a better detail.

      • OK, with the tips above, you should think of what I want to say next, is our return button of the range of receiving events will be magnified, of course, this is only one of my conjecture, then if my guess succeeds, now is the situation, the middle of a push key does not click after push, But his response range is magnified, so the middle click is Normal, the border click will invoke the push method, so the conjecture seems reasonable, this conjecture and the above kind of conjecture should be more reasonable, but it is conjecture.

  • As for the solution, very simple, I guess you also think of, but why this bug, this is the most important, at least the school attitude is not wrong, the solution: basically:

    • If it is a custom navigation, you can check in the overridden push method whether the controller is already present in the navigation.
    -(BOOL) Checkisexit: (ID) vc{for    (id classobj in self.childviewcontrollers) {        Class class = [Classobj class];        if ([VC Iskindofclass:class]) {            return YES;        }    }    return NO;}
      • If the system comes with, you can decide whether to take the last one when the navigation's childrencontrollers count changes, this may use KVO, it is necessary to remind that the system KVO is not available for all attributes, If you are using Swift to recommend a third-party framework Observable-Swift , this framework is a good use of swift generics, if OC, to find the framework on GitHub on its own.

Uinavgation Everyday Small bug-interested friends can see

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.