任何人都可以向我解释一下,当谈到UITableView时,MVC是如何工作的,尤其是从互联网上获取数据时.
我想知道UItableview的模型,视图和控制器是什么
我编写了以下ViewController代码,该代码从Internet获取数据并使用AFNetworking框架将其显示在表中.
您能告诉我如何更改它并将其分为模型,视图和控制器.我还写了一个刷新类,我猜这是模型的一部分.你能告诉我我是如何做出改变并使其成为模型的一部分.
编辑:以下答案帮助我理解理论上的概念,有人可以帮助我相应地更改代码(通过编写一个关于如何调用数组到这个类并填充表的新类,因为我使用的是json解析器).我想实现它.而不只是从理论上理解它.
#import "ViewController.h"
#import "AFNetworking.h"
@implementation ViewController
@synthesize tableView = _tableView, activityIndicatorView = _activityIndicatorView, movies = _movies;
- (void)viewDidLoad {
[super viewDidLoad];
// Setting Up Table View
self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0.0, 0.0, self.view.bounds.size.width, self.view.bounds.size.height) style:UITableViewStylePlain];
self.tableView.dataSource = self;
self.tableView.delegate = self;
self.tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.tableView.hidden = YES;
[self.view addSubview:self.tableView];
// Setting Up Activity Indicator View
self.activityIndicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
self.activityIndicatorView.hidesWhenStopped = YES;
self.activityIndicatorView.center = self.view.center;
[self.view addSubview:self.activityIndicatorView];
[self.activityIndicatorView startAnimating];
// Initializing Data …Run Code Online (Sandbox Code Playgroud)