iOS video project parsing is mainly about block details if you know the definition of block, but not very familiar with the use of this article

Source: Internet
Author: User
<span id="Label3"></p><p style="text-align: center;"><p style="text-align: center;"><span style="background-color: #000000;"><span style="color: #888888; font-family: 黑体; font-size: medium;"><span style="line-height: 24px;">Video project analysis from GitHub</span></span></span></p></p><p style="text-align: center;"><p style="text-align: center;"><span style="background-color: #000000;"><span style="color: #888888; font-family: 黑体; font-size: medium;"><span style="line-height: 24px;">This project can be downloaded on both 4app and github.</span></span></span></p></p><p style="text-align: center;"><p style="text-align: center;"></p></p><p style="text-align: left;"><p style="text-align: left;"><span style="color: #888888; font-family: 黑体; font-size: medium;"><span style="line-height: 24px;">Project:</span></span><span style="line-height: 1.5;"><br></span></p></p><p style="text-align: left;"><p style="text-align: left;"><span style="color: #888888; font-family: 黑体; font-size: medium;"><span style="line-height: 24px;"><span style="font-size: 14px; color: #993300;">Here is the program just run interface</span><br></span></span></p></p><p style="text-align: left;"><p style="text-align: left;"><span style="color: #888888; font-family: 黑体; font-size: medium;"><span style="line-height: 24px;"><span style="font-size: 14px; color: #993300;">The program should have a Discover controller</span></span></span></p></p><p style="text-align: left;"><p style="text-align: left;"><span style="color: #888888; font-family: 黑体; font-size: medium;"><span style="line-height: 24px;"><span style="font-size: 14px; color: #993300;">Find the Discover controller, and then you can familiarize yourself with the principles of the project based on the Project's process to learn their architectural ideas</span></span></span></p></p><p style="text-align: left;"><p style="text-align: left;"></p></p><pre><span style="color: #008080;"><span style="color: #008080;">1</span></span>- (<span style="color: #0000ff;"><span style="color: #0000ff;">void</span></span><span style="color: #000000;"><span style="color: #000000;">) Setuptableview</span></span><span style="color: #008080;"><span style="color: #008080;">2</span></span> <span style="color: #000000;"><span style="color: #000000;">{</span></span><span style="color: #008080;"><span style="color: #008080;">3</span></span> <span style="color: #0000ff;"><span style="color: #0000ff;">if</span></span>(!<span style="color: #000000;"><span style="color: #000000;">_refreshcontrol)</span></span><span style="color: #008080;"><span style="color: #008080;">4</span></span> <span style="color: #000000;"><span style="color: #000000;"> {</span></span><span style="color: #008080;"><span style="color: #008080;">5</span></span>_refreshcontrol = [[uirefreshcontrol alloc] initwithframe:cgrectmake (<span style="color: #800080;"><span style="color: #800080;">0</span></span>, -<span style="color: #800080;"><span style="color: #800080;"></span> -</span>,<span style="color: #800080;"><span style="color: #800080;"></span> the</span>,<span style="color: #800080;"><span style="color: #800080;"></span> -</span><span style="color: #000000;"><span style="color: #000000;">)];</span></span><span style="color: #008080;"><span style="color: #008080;">6</span></span> <span style="color: #000000;"><span style="color: #000000;">[self.refreshcontrol addtarget:self action: @selector (refreshfeed) forcontrolevents:uicontroleventvaluechange d];</span></span><span style="color: #008080;"><span style="color: #008080;">7</span></span> <span style="color: #000000;"><span style="color: #000000;">[self.tableview addsubview:_refreshcontrol];</span></span><span style="color: #008080;"><span style="color: #008080;">8</span></span> <span style="color: #000000;"><span style="color: #000000;"> }</span></span><span style="color: #008080;"><span style="color: #008080;">9</span></span>}</pre><p style="text-align: left;"><p style="text-align: left;"></p></p><p><p>Here you can see that the addition of a refresh space takes lazy loading</p></p><pre><pre>-(<span style="color: #0000ff;">void</span><span style="color: #000000;">) refreshfeed{ [self requestmovies];}</span></pre></pre><p><p>He calls requestmovies this method at the moment of viewdidload and the change of the refresh control</p></p><p><p>Find this method</p></p><pre><pre>-(<span style="color: #0000ff;">void</span><span style="color: #000000;">) requestmovies{ </span>= ^ (nsarray* data, nsstring*<span style="color: #000000;"> errorstring) { [ Self.refreshcontrol endrefreshing]; </span> <span style="color: #0000ff;">if</span> (data! =<span style="color: #000000;"> Nil) [self processdata:data]; </span> <span style="color: #0000ff;">Else</span> <span style="color: #000000;"> [self.networkloadingviewcontroller showerrorview]; }; Kmdiscoversource</span>* Source =<span style="color: #000000;"> [kmdiscoversource discoversource]; [source getdiscoverlist:</span> <span style="color: #800000;">@"</span> <span style="color: #800000;">1</span> <span style="color: #800000;">"</span> <span style="color: #000000;">completion:completionblock];}</span></pre></pre><p><p>It's been a long time here to understand that the block ahead is a call to the BACK.</p></p><p><p>Can also be written like this run completely without errors</p></p><pre><pre>kmdiscoversource* Source =<span style="color: #000000;"> [kmdiscoversource discoversource]; [source getdiscoverlist:</span> <span style="color: #800000;">@"</span> <span style="color: #800000;">1</span> <span style="color: #800000;">"</span> completion:^ (nsarray *data, nsstring *<span style="color: #000000;">errorstring) { [self.refreshcontrol endrefreshing]; </span> <span style="color: #0000ff;">if</span> (data! =<span style="color: #000000;"> Nil) [self processdata:data]; </span> <span style="color: #0000ff;">Else</span> <span style="color: #000000;"> [self.networkloadingviewcontroller showerrorview]; } ]; </span></pre></pre><p><p></p></p><p><p>The meaning of this inside</p></p><p><p>Here he will download the data method encapsulated as a block this is my main way to look at the block is always not very familiar with</p></p><p><p>Just go in and Look.</p></p><pre><pre><span style="color: #0000ff;">#import</span> <span style="color: #800000;">"</span> <span style="color: #800000;">KMBaseSource.h</span> <span style="color: #800000;">"</span> <span style="color: #000000;"></span> <span style="color: #0000ff;">void</span> (^kmdiscoverlistcompletionblock) (nsarray* data, nsstring*<span style="color: #000000;"> errorstring);</span> <span style="color: #0000ff;">@interface</span> <span style="color: #000000;">kmdiscoversource:kmbasesource</span>+ (kmdiscoversource*<span style="color: #000000;">) discoversource;</span> -(<span style="color: #0000ff;">void</span>) getdiscoverlist: (nsstring*<span style="color: #000000;">) pagelimit completion: (kmdiscoverlistcompletionblock) completionblock;</span> <span style="color: #0000ff;">@end</span></pre></pre><p><p>This should be a tool class for returning discover Data.</p></p><pre><span style="color: #008080;"><span style="color: #008080;">1</span></span>- (<span style="color: #0000ff;"><span style="color: #0000ff;">void</span></span>) Getdiscoverlist: (nsstring*<span style="color: #000000;"><span style="color: #000000;">) pagelimit completion: (kmdiscoverlistcompletionblock) completionblock;</span></span><span style="color: #008080;"><span style="color: #008080;">2</span></span> <span style="color: #000000;"><span style="color: #000000;">{</span></span><span style="color: #008080;"><span style="color: #008080;">3</span></span> <span style="color: #0000ff;"><span style="color: #0000ff;">if</span></span><span style="color: #000000;"><span style="color: #000000;">(completionblock)</span></span><span style="color: #008080;"><span style="color: #008080;">4</span></span> <span style="color: #000000;"><span style="color: #000000;"> {</span></span><span style="color: #008080;"><span style="color: #008080;">5</span></span>nsdictionary* parameters = [[nsdictionary alloc] initwithobjects:[nsarray arraywithobjects:pagelimit, nil] forKeys:[ Nsarray arraywithobjects:<span style="color: #800000;"><span style="color: #800000;">@"</span></span><span style="color: #800000;"><span style="color: #800000;">page</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #000000;"><span style="color: #000000;">, nil]];</span></span><span style="color: #008080;"><span style="color: #008080;">6</span></span> <span style="color: #008080;"><span style="color: #008080;">7</span></span>[uiapplication sharedapplication].networkactivityindicatorvisible =<span style="color: #000000;"><span style="color: #000000;">YES;</span></span><span style="color: #008080;"><span style="color: #008080;">8</span></span> <span style="color: #008080;"><span style="color: #008080;">9</span></span>Afhttprequestoperationmanager *manager =<span style="color: #000000;"><span style="color: #000000;">[afhttprequestoperationmanager manager];</span></span><span style="color: #008080;"><span style="color: #008080;">Ten</span></span>[manager.requestserializer setValue:<span style="color: #800000;"><span style="color: #800000;">@"</span></span><span style="color: #800000;"><span style="color: #800000;">Application/json</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span>Forhttpheaderfield:<span style="color: #800000;"><span style="color: #800000;">@"</span></span><span style="color: #800000;"><span style="color: #800000;">Accept</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #000000;"><span style="color: #000000;">];</span></span><span style="color: #008080;"><span style="color: #008080;"></span> one</span> <span style="color: #008080;"><span style="color: #008080;"></span> a</span>[manager get:[self prepareurl] parameters:parameters success:^ (afhttprequestoperation *operation,<span style="color: #0000ff;"><span style="color: #0000ff;">ID</span></span><span style="color: #000000;"><span style="color: #000000;">Responseobject)</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #000000;"><span style="color: #000000;"> {</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span>NSLog (<span style="color: #800000;"><span style="color: #800000;">@"</span></span><span style="color: #800000;"><span style="color: #800000;">JSON:%@</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #000000;"><span style="color: #000000;">, responseobject);</span></span><span style="color: #008080;"><span style="color: #008080;"></span> the</span>nsdictionary* infosdictionary = [self dictionaryFromResponseData:operation.responseData jsonpatternfile:<span style="color: #800000;"><span style="color: #800000;">@"</span></span><span style="color: #800000;"><span style="color: #800000;">Kmdiscoversourcejsonpattern.json</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #000000;"><span style="color: #000000;">];</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span>Dispatch_async (dispatch_get_main_queue (), ^<span style="color: #000000;"><span style="color: #000000;">{</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span>[uiapplication sharedapplication].networkactivityindicatorvisible =<span style="color: #000000;"><span style="color: #000000;">NO;</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #000000;"><span style="color: #000000;">completionblock ([self processresponseobject:infosdictionary], nil);</span></span><span style="color: #008080;"><span style="color: #008080;"></span> +</span> <span style="color: #000000;"><span style="color: #000000;"> });</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #000000;"><span style="color: #000000;"> }</span></span><span style="color: #008080;"><span style="color: #008080;"></span> +</span>failure:^ (afhttprequestoperation *operation, Nserror *<span style="color: #000000;"><span style="color: #000000;">Error)</span></span><span style="color: #008080;"><span style="color: #008080;"></span> a</span> <span style="color: #000000;"><span style="color: #000000;"> {</span></span><span style="color: #008080;"><span style="color: #008080;"></span> at</span>NSLog (<span style="color: #800000;"><span style="color: #800000;">@"</span></span><span style="color: #800000;"><span style="color: #800000;">Error:%@</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #000000;"><span style="color: #000000;">, error);</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span>Dispatch_async (dispatch_get_main_queue (), ^<span style="color: #000000;"><span style="color: #000000;">{</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span>[uiapplication sharedapplication].networkactivityindicatorvisible =<span style="color: #000000;"><span style="color: #000000;">NO;</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span>nsstring* errorstring =<span style="color: #000000;"><span style="color: #000000;">error.localizeddescription;</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #0000ff;"><span style="color: #0000ff;">if</span></span>([errorstring length] = =<span style="color: #800080;"><span style="color: #800080;">0</span></span><span style="color: #000000;"><span style="color: #000000;">)</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span>ErrorString =<span style="color: #000000;"><span style="color: #000000;">nil;</span></span><span style="color: #008080;"><span style="color: #008080;"></span> in</span> <span style="color: #000000;"><span style="color: #000000;">completionblock (nil, errorstring);</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #000000;"><span style="color: #000000;"> });</span></span><span style="color: #008080;"><span style="color: #008080;"></span> to</span> <span style="color: #000000;"><span style="color: #000000;"> }];</span></span><span style="color: #008080;"><span style="color: #008080;"></span> +</span> <span style="color: #000000;"><span style="color: #000000;"> }</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span>}</pre><p><p>The Third-party framework is used here AFN</p></p><p><p>The first sentence is to pass in a dictionary parameter</p></p><p><p>Line 7th shows the network Transport icon for the status bar</p></p><p><p>The 12th behavior sends a GET request</p></p><p><p>The 15th line is the json-parsed package because AFN is executed asynchronously, so to get the main thread update UI to the block parameters of the data to block and then the other controller call this block when there will be parameters can also do their own operation can see this method, also You can listen to this data download Yes No</p></p><p><p>Because the argument in err is that nil is judged by the line at run Time.</p></p><pre>-(nsarray*) processresponseobject: (nsdictionary*<span style="color: #000000;"><span style="color: #000000;">) data{</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">if</span></span>(data = =<span style="color: #000000;"><span style="color: #000000;">Nil)</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">return</span></span><span style="color: #000000;"><span style="color: #000000;">nil; Nsarray</span></span>* itemslist = [nsarray Arraywitharray:[data objectforkey:<span style="color: #800000;"><span style="color: #800000;">@"</span></span><span style="color: #800000;"><span style="color: #800000;">Results</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #000000;"><span style="color: #000000;">]]; Nsmutablearray</span></span>* Sortedarray =<span style="color: #000000;"><span style="color: #000000;">[[nsmutablearray alloc] init]; </span></span><span style="color: #0000ff;"><span style="color: #0000ff;"></span> for</span>(nsdictionary* Item<span style="color: #0000ff;"><span style="color: #0000ff;">inch</span></span><span style="color: #000000;"><span style="color: #000000;">Itemslist) {kmmovie</span></span>* Movie =<span style="color: #000000;"><span style="color: #000000;">[[kmmovie alloc] initwithdictionary:item]; [sortedarray addobject:movie]; } </span></span><span style="color: #0000ff;"><span style="color: #0000ff;">return</span></span><span style="color: #000000;"><span style="color: #000000;">sortedarray;}</span></span></pre><p><p>It is clear to see that this function has a dictionary</p></p><p><p>-------------------not to Be Continued</p></p><p><p></p></p><p><p></p></p><p style="text-align: left;"><p style="text-align: left;"></p></p><p><p>iOS video project parsing is mainly about block details if you know the definition of block, but not very familiar with the use of this article</p></p></span>

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.