UITableView的使用和点击每个cell跳转到其他controller优化
来源:互联网 发布:手游推广联盟源码 编辑:程序博客网 时间:2024/05/29 11:16
一、需要一个NSObject类,该类代码如下
#import <Foundation/Foundation.h>
@interface MJSampleIndex :NSObject
@property (nonatomic,copy) NSString *title; //描述该类的title
@property (nonatomic,assign) Class controllerClass; //跳转到的controller
+ (instancetype)sampleIndexWithTitle:(NSString *)title controllerClass:(Class)controllerClass; //初始化title和controller
@end
#import "MJSampleIndex.h"
@implementation MJSampleIndex
+ (instancetype)sampleIndexWithTitle:(NSString *)title controllerClass:(Class)controllerClass
{
MJSampleIndex *si = [[selfalloc] init];
si.title = title;
si.controllerClass = controllerClass;
return si;
}
@end
二、UITableViewController方法实现三个方法:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section //tableview总行数
{
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath //根据行数绘制tableviewcell
{}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath //点击每个cell执行的事件
{}
#import "MJSampleIndexViewController.h"
#import "MJSampleIndex.h"
#import "MJTableViewController.h"
#import "MJCollectionViewController.h"
NSString *const MJSampleIndexCellIdentifier =@"Cell";
@interface MJSampleIndexViewController ()
{
NSArray *_sampleIndexs;
}
@end
@implementation MJSampleIndexViewController
- (void)viewDidLoad
{
[superviewDidLoad];
self.title =@"快速集成下拉刷新";
self.navigationItem.backBarButtonItem = [[UIBarButtonItemalloc] initWithTitle:@"返回"style:UIBarButtonItemStyleBorderedtarget:nilaction:nil];
// 1.注册cell
[self.tableViewregisterClass:[UITableViewCellclass] forCellReuseIdentifier:MJSampleIndexCellIdentifier];
// 2.初始化数据
MJSampleIndex *si1 = [MJSampleIndexsampleIndexWithTitle:@"tableView刷新演示"controllerClass:[MJTableViewControllerclass]];
MJSampleIndex *si2 = [MJSampleIndexsampleIndexWithTitle:@"collectionView刷新演示"controllerClass:[MJCollectionViewControllerclass]];
_sampleIndexs =@[si1, si2];
}
#pragma mark - Table view data source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return_sampleIndexs.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableViewdequeueReusableCellWithIdentifier:MJSampleIndexCellIdentifierforIndexPath:indexPath];
// 1.取出模型
MJSampleIndex *si =_sampleIndexs[indexPath.row];
// 2.赋值
cell.textLabel.text = si.title;
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// 1.取出模型
MJSampleIndex *si =_sampleIndexs[indexPath.row];
// 2.创建控制器
UIViewController *vc = [[si.controllerClassalloc] init];
vc.title = si.title;
// 3.跳转
[self.navigationControllerpushViewController:vc animated:YES];
}
@end
- UITableView的使用和点击每个cell跳转到其他controller优化
- UITableView中点击不同Cell跳转到不同的View
- UItableView 点击cell跳转到其它界面延迟bug
- UItableView 点击cell跳转到其它界面延迟bug
- 代码实现UITableView点击cell跳转
- 实现UITableView中点击不同cell进入不同Controller的方法
- 点击每个省份的并跳转到各自的界面
- UITableView中的cell的优化
- 获取到UITableView的cell
- iOS代码自定义UITableView Cell(每个Cell的高度不一样)
- 不使用a标签,实现点击跳转到其他页面的代码
- 点击UITableView的cell展开收缩
- 点击UITableView的cell展开收缩
- 点击UITableView的cell展开收缩
- UITableView指定Cell的点击区域
- 点击UITableView的cell展开收缩
- UITableView点击cell时有延迟的解决办法
- 点击UITableView的cell展开收缩
- noip2004 津津的储蓄计划 (模拟)
- HDU1269-迷宫城堡
- 【坑】javascript中让setTimeout方法间隔时间更为精确
- spring mvc + MyBatis + Easyui
- 1148 -- 小光棍数
- UITableView的使用和点击每个cell跳转到其他controller优化
- android 学习笔记 光照传感器的用法
- UIAlertView在其他页面快速显示?
- Ambari2.1安装hdp2.3
- 1149 -- 光棍节的快乐
- ReactiveCocoa-基础
- 面试之jsp、Servlet相关知识——生命周期,区别等
- Hadoop第9周练习—Hive部署测试(含MySql部署)
- 相关滤波跟踪(MOSSE)