接着我前两篇的登陆继续做,要完成登录成功后显示出导航控制器Nav,再通过Nav里的跳转实现UITableView,效果如下
首先对登录界面进行一下修改,在LoginViewController.h中新添加一个输出口@interface _1_11LoginViewController : UIViewController {
IBOutlet UITextField *namefield;
IBOutlet UITextField *passwordfield;
IBOutlet UINavigationController *rootController;
}
@property (nonatomic,retain) UITextField *namefield;
@property (nonatomic,retain) UITextField *passwordfield;
@property (nonatomic,retain) UINavigationController *rootController;
-(IBAction)login;
-(IBAction)namefieldEditing:(id)sender;
-(IBAction)changeTextFile;
-(IBAction)doneLogin;
@end
对.h文件在修改
-(IBAction)login{
if (namefield.text.length<4||passwordfield.text.length<4) {
NSLog(@"++++++++++");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Wrong"
message:@"They are not long enough"
delegate:self
cancelButtonTitle:@"I konw"
otherButtonTitles:nil];
[alert show];
[alert release];
}else {
[self.view.window addSubview:rootController.view];
}
}
再创建两个新类和相应的.xib文件,分别取名successLogin,listViewController。我们再去关注一下LoginViewController.xib文件,拖一个navigation Controller图标到nib主窗口中,那么则新弹出一个视图窗口,按住Ctrl将File‘s Owner拖向Navigation Controller,在选中nib主窗口的第二项
点选图中蓝色区域,再看他的控制器,分别对其修改为
目的是将导航器的方向定位success类和其视图。
我们再对success.xib进行设置,只加入一个按钮,并做相应的关联,对他的.h文件进行编码
@interface successLogin : UIViewController {
}
-(IBAction)showPressed;
@end
对.m文件进行编码
#import "successLogin.h"
#import "ListViewController.h"
@implementation successLogin
-(IBAction)showPressed{
ListViewController *myListViewController = [[ListViewController alloc] initWithNibName:@"ListViewController" bundle:nil];
[self.navigationController pushViewController:myListViewController animated:YES];
[myListViewController release];
}
下面创建最后一个视图,向视图中拖入一个TableView,选中该控件,按花+2键,将delegate和dataSource都与File‘s Owner连接
对.h文件进行编码
@interface ListViewController : UIViewController
<UITableViewDelegate,UITableViewDataSource>{
IBOutlet UITableView *myTableView;
NSArray *friendList;
}
@property (nonatomic,retain)UITableView *myTableView;
@property (nonatomic,retain)NSArray *friendList;
@end
对.m文件进行编码
#import "ListViewController.h"
@implementation ListViewController
@synthesize friendList;
@synthesize myTableView;
- (void)viewDidLoad {
[super viewDidLoad];
NSArray *array= [[NSArray alloc] initWithObjects:@"劳尔",@"穆里尼奥",@"卡卡",@"罗尼",@"小贝",nil];
self.friendList=array;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (void)viewDidUnload {
[super viewDidUnload];
}
- (void)dealloc {
[myTableView release];
[friendList release];
[super dealloc];
}
//添加每一行的信息
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *tag=@"tag";
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:tag];
if (cell==nil) {
cell=[[[UITableViewCell alloc] initWithFrame:CGRectZero
reuseIdentifier:tag] autorelease];
}
[cell.textLabel setText:[self.friendList objectAtIndex:[indexPath row]]];
UIImage *image=[UIImage imageNamed:@"30.png"];//每行添加图片
cell.image=image;
return cell;
}
//添加行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.friendList count];
}
//使列表重复出现次数
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 6;
}
//选中哪一行
-(NSIndexPath *)tableView:(UITableView *)tableView
willSelectRowAtIndexPath:(NSIndexPath *)indexpath
{
NSUInteger row=[indexpath row];
if (row==0) {
return nil;
}
return indexpath;
}
//选中之后的处理
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSUInteger row=[indexPath row];
NSString *rowvalue=[friendList objectAtIndex:row];
NSString *message=[[NSString alloc] initWithFormat:@"你选中了 %@", rowvalue];
UIAlertView *alert=[[UIAlertView alloc]
initWithTitle:@"恭喜"
message:message
delegate:nil
cancelButtonTitle:@"知道了"
otherButtonTitles:nil];
[alert show];
[message release];
[alert release];
}
@end
完成了。
- 大小: 301.2 KB
- 大小: 80.6 KB
- 大小: 107.1 KB
- 大小: 66.5 KB
- 大小: 24.8 KB
- 大小: 18.1 KB
- 大小: 17 KB
- 大小: 17.2 KB
分享到:
相关推荐
UITableView表视图和导航控制器的交互使用
NULL 博文链接:https://andli.iteye.com/blog/1610135
iOS使用UITableView实现的富文本编辑器iOS使用UITableView实现的富文本编辑器iOS使用UITableView实现的富文本编辑器iOS使用UITableView实现的富文本编辑器iOS使用UITableView实现的富文本编辑器iOS使用UITableView...
UITableView是iPhone中比较常用的,用的比较多的控件, 本例中说明iPhone UITableView的使用方法实例。 该实列中是手动增加UITableViewDataSource和UITableViewDelegate协议来实现的。
UITableView的使用 包括简单的搭建UITableView、搭建分组的UITableView、搭建分段的UITableView、可删除行等等
UITableView的简单使用
UITableView、UITableView基本用法、UITableView详解,UITabelView常用方法
UICollectionView和UITableView切换
一个控制器同时加载两个UITableView, 并分栏显示 (京东网页分栏的效果)
UITableView相关操作
里面有很多uitableview和uinavigation等控件用法
在iOS开发中会用到的UISCrollView与UITableView嵌套使用的方法
UITableView的使用,UITableView所在的UIViewController声明两个delegate:UITableViewDelegate和UITableViewDataSource。
UITableView Demo 快捷菜单 粘贴 Cell
IOS代码中使用自定义UITableView,包含了一些开发过程中需要注意的地方
使用的是MVC编程框架,KVO数据模型,仅供参考
代码仅供参考,有问题可以 联系我
UITableViewDropDown 点击cell展开另外一个UITableView
UITableView通过重用单元格来达到节省内存的目的:通过为每个单元格指定一个重用标识符 reuseIdentifier 即指定了单元格的种类 以及当单元格滚出屏幕时 允许恢复单元格以便重用 对于不同种类的单元格使用不同的ID ...
TreeView for iPhone,《使用UITableView实现树视图》一文源代码