K
K
Konstantin2013-11-22 16:37:39
iOS
Konstantin, 2013-11-22 16:37:39

An example of using MVC in iOS - complex control device + interaction?

I want to take a closer look at using the MVC pattern in iOS. I have a basic understanding, but for more complex cases, understanding is not enough.
1. For example, how is UITableView arranged? On the one hand, it's just a View interacting with my controller. On the other hand, there is a complex control (control / ui). It has quite a variety of behavior: individual cell swipes, edit mode, cell reordering, sections, quick jump sections… I guess
there might be the same MVC split inside. That is, for the programmer, this is a View, but the Controller sits inside, with which the programmer communicates. And already this controller is engaged in receiving cells, their caching, display and other bells and whistles.
Or here all the logic is contained directly in the View and there is no separation.
With this ± it is clear, although I do not know for sure whether it is implemented this way.
If anyone has clarifications / examples of the implementation of such a miracle, please share.
2. Further it is more incomprehensible.
UITableView has a wonderful ability: to be combined with UISearchBar. Although, rather, it is the ability of UISearchBar. Interested in changing the "table" after activating the search field. In this case, the UISearchBar moves up, embedding in the UINavigationBar. And behind it "pulls" UITableView.
Also, the UISearchBar in Safari is harmoniously integrated with UIWebView - it smoothly hides in the "navi bar" when scrolling the page.
The question is: how is such interaction implemented and how is it consistent with MVC?
I will also gladly accept book titles and links to sensible articles about MVC in iOS.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
N
Ne0nX, 2013-11-23
@Ne0nX

1) Read https://developer.apple.com/Library/ios/documentation/UIKit/Reference/UITableView_Class/Reference/Reference.html
This is a regular UIScrollView, it contains (subviews) in our case UITableViewCell, well, more extra goodies )
2)

UITableView *tableView = ...;
UISearchBar searchBar = ....;

tableView.tableHeaderView = searchBar; // Теперь SearchBar всегда над вашими ячейками.

In Safari, most likely, a regular custom View is used and it is not related to UINavigationController and UINavigationBar.
Everything is hidden using normal animations
//Псевдокод 
//Y = высота экрана + высота View
[UIView animateWithDuration:<#(NSTimeInterval)#> animations:^{
        view.frame = CGRectMake(x, <Y> ,width,height);
}];

At the expense of MVC, everything is very simple.
The user sees views (views), with their help he communicates with the controller, and the controller already communicates with Models (Models),

A
Alexander, 2013-11-23
@alexyat

MVC in iOS is quite specific, the main thing for you is to understand what it means and what you need - Model is a model (this is your data), View is a view (these are buttons, labels, everything that is visible) and Control is logic, auxiliary methods and classes which in most cases help to interact with the first two. It is important for you to understand that all these things should be separated so that you can easily change individual parts so that you do not mix data and interface.

I
IURIA, 2013-12-02
@GxocT

Read this material: www.objc.io/issue-1/
The authors explain which logic, in their opinion, should be placed in the ViewController, and which should be transferred to the Model or View. I think after that you will have much fewer questions, you will be able to formulate your point of view and get better at MVC :-)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question