<< proficient in iOS development >> 14th example code minor bug fixes

Source: Internet
Author: User

Panda Pig • Patty original or translated works. Welcome reprint, Reprint please indicate the source.
If you feel that the writing is not good please more advice, if you feel good please support a lot of praise. Thank you! Hopy;)

First recommend everyone read this book, the whole book logic is very clear, how the code from scratch, to plump said very organized.

To tell the truth, the book so far the error is very few, but nobody is perfect, in the first half of the 14th chapter of the project code, the author in mastervc to DETAILVC and directly added a segue, the Segue ID is "Mastertodetail", The effect is that when you create a new Tinypix document, you can jump directly to DETAILVC to edit the document.

The author also realizes that if you go directly from the MASTERVC table view cell directly to DETAILVC, you need to do some extra work, which is to jump to the DETAILVC and open the existing document when the user clicks on the existing Tinypix.

The author is so modified Prepareforsegue:: Method of:

-(void) Prepareforsegue: (Uistoryboardsegue *) Segue Sender: (ID) sender{if(Sender = = Self) {Uiviewcontroller*destination = Segue. Destinationviewcontroller;if([Destination Respondstoselector:@selector(Setdetailitem:)]) {[Destination Setvalue:_chosendoc forkey:@"Detailitem"]; }    }Else{Nsindexpath*indexpath = Self. TableView. Indexpathforselectedrow;NSString*filename = _docfilenames[indexpath. Row];Nsurl*docurl = [ SelfUrlforfilename:filename];        _chosendoc = [[Hytinypixdocument Alloc]initwithfileurl:docurl]; [_chosendoc openwithcompletionhandler:^ (BOOLSuccess) {if(success) {Uiviewcontroller*destination = Segue. Destinationviewcontroller;if([Destination Respondstoselector:@selector(Setdetailitem:)]) {[Destination Setvalue:_chosendoc forkey:@"Detailitem"]; }            }Else{NSLog(@"failed to load!");    }        }]; }}

However, when you actually execute the app, you find that clicking on an existing Tinypix file does not correctly display the contents of the document in DETAILVC. The next breakpoint after the else branch of the above method, Find the code that Tableviewcell jumps to, whose segue.destinationviewcontroller is not the detailviewcontroller we want, It is uinavigationcontroller. And the latter naturally does not exist God Horse Setdetailitem: Method.

I don't know if this is the author's clerical error or something else, or is there a change in the Master-detail application template in the new version of Xcode? But at least in Xcode7.2, that's the case.

So how do you fix the problem? It's actually simpler than you think, and it's modified as follows:

if (success) {                //UIViewController *destination = segue.destinationViewController;                DetailViewController *detailVC = (DetailViewController*)[                                        segue.destinationViewController topViewController];                if ([detailVC respondsToSelector:@selector(setDetailItem:)]) {                    setforKey:@"detailItem"];                }            }else{                NSLog(@"failed to load!");            }

What we need here is the DESTINATIONVC Topviewcontroller object, not the DESTINATIONVC itself.

To compile the connection app, now both approaches to DETAILVC are behaving normally:

<< Proficient in iOS development >> 14th example code minor bug fixes

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.