IOS菜鸟的所感所思——UITableView中数据之间的顺序与反向传递

本文介绍了一个iOS新手在使用UITableView时遇到的数据顺序传递和反向传递的问题及解决方案。通过创建项目,设置UITableView,定义数据源,实现协议和委托方法,详细解释了如何在两个UIViewController之间进行数据的传递和接收,包括从ViewController到MyPicturesViewController的正向传递,以及从MyPicturesViewController回传到ViewController的反向传递。最后,文章提到了如何根据选择的行显示对应图片的方法。
摘要由CSDN通过智能技术生成

这是我的第一篇关于IOS的文章,可能有些不对的地方,希望大家指正。

步骤:
一:
1.建立一个项目,其ViewController的类型是UITableViewController,设置其identifier——MyTextCell;(点击viewcontroller的控制器后 点击上面的标题栏Editor中的embed in中的Navigation)
2.添加一个新的controller,MyPicturesViewController继承UITableViewController,设置其identifier——MyPicCell;
3.建立segue,从ViewController的控制器按住ctrl添加segue到MyPicturesViewController,选择show,其segue的identifier是ShowPic
初步的view视图工作完成了。



第二部分就是代码的,
二:
1.为ViewController添加数据源,创建newGroup——ModelClass,在ModelClass中创建cocoa Touch class的NSObject类ViewControllerInfo。
2.在ViewControllerInfo中初始化一些信息


ViewControllerInfo.h文件中:

#import<Foundation/Foundation.h>

@interface ViewControllerInfo :NSObject

@property (nonatomic,strong)NSArray *cellInfo;

@end


ViewControllerInfo.m文件中:

#import "ViewControllerInfo.h"

@implementation ViewControllerInfo

- (id)init{

    if (self = [superinit]) {

        [selfinitCellInfo];

    }

    return self;

}

- (void)initCellInfo{

    _cellInfo = [[NSArrayalloc]initWithObjects:@"内容一",@"内容二",@"内容三",nil];

}

@end

ViewController.m文件中:


3.给ViewController中的Cell初始化内容。

#import "ViewController.h"

#import "ViewControllerInfo.h"

#import "MyPicturesViewController.h"


@interfaceViewController ()


@property (nonatomic,strong)ViewControllerInfo *viewInfo;


@end


@implementation ViewController


- (void)viewDidLoad {

    [superviewDidLoad];

    [selfconfigureViewInfo];

}

//加载数据。

- (void)configureViewInfo{

    _viewInfo = [[ViewControllerInfoalloc]init];

}

//行数

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    returnself.viewInfo.cellInfo.count;

}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{

   return1;

}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)in

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值