您的位置:首页 > 产品设计 > UI/UE

UIViewController

2014-06-10 23:03 369 查看
//----------------标题

self.title =
@"联系人资料";

//----------------标题栏不透明度

self.navigationController.navigationBar.translucent =
NO;

//----------------背景颜色

self.view.backgroundColor = [WebColor
white];

//----------------按钮字体颜色

self.navigationController.navigationBar.tintColor = [UIColor
redColor];

//----------------添加附加样子

.accessoryType =
UITableViewCellAccessoryDisclosureIndicator;

//----------------标题栏按钮(左右)

self.navigationItem.leftBarButtonItem
= [[[UIBarButtonItem
alloc] initWithTitle:@"添加联系人"
style:UIBarButtonItemStyleBordered target:self action:@selector(click:)]
autorelease];

//----------------设置标题背景颜色

self.navigationController.navigationBar.barTintColor = [WebColor
pink];

//----------------匹配view高度

self.view.frame.size.height
- 64

//----------------上左下右的距离
UITableView.separatorInset =
UIEdgeInsetsMake(0,
40, 0,
10);

//----------------线条颜色

UITableView.separatorColor = [UIColor
grayColor];

//----------------设置代理
UITableView.dataSource =
self;

//----------------代理
UITableView.delegate =
self;

//----------------线条间隔
UITableView.rowHeight =
80;

//----------------设定Header的高度,

UITableView.sectionHeaderHeight
= 50;

//----------------设定footer的高度,

UITableView.sectionFooterHeight
= 100;

//----------------跳到指的row or section

[UITableView scrollToRowAtIndexPath:[NSIndexPath
indexPathForRow:0
inSection:1]

                       
atScrollPosition:UITableViewScrollPositionBottom
animated:NO];

//----------------设定cell分行线的样式,默认为UITableViewCellSeparatorStyleSingleLine

UITableView.separatorStyle =
UITableViewCellSeparatorStyleSingleLineEtched;

//----------------刷新界面(重新载入所有数据)

[tableview reloadData];

//----------------进入下一个视图
是否有动画(YES)

[self.navigationController
pushViewController:view animated:YES];

//----------------返回到上一个视图

[self.navigationController
popViewControllerAnimated:YES];

//----------------返回到根视图

[self.navigationController
popToRootViewControllerAnimated:YES];

//----------------返回到指定视图

[self.navigationController
popToViewController:[self.navigationController.viewControllers
objectAtIndex:1]
animated:YES];

//----------------调用代理中的方法   (判断是否登陆)

[self.Delegate
isRegister];

//----------------让页面弹回去

[self
dismissViewControllerAnimated:NO
completion:NULL];

//----------------设置没选中之前的背景颜色

cell.contentView.backgroundColor = [UIColor
clearColor];

//----------------未选cell时的图片

cell.imageView.image=[UIImage
imageNamed:@"1001.jpg"];

//----------------选中cell后的图片

cell.imageView.highlightedImage=[UIImage
imageNamed:@"1002.jpg"];

//----------------未知方法
cell.textLabel.text=[[self.myDic objectForKey:[[self.myDic allKeys]objectAtIndex:indexPath.section]]objectAtIndex:indexPath.row];

//----------------自定义选中cell时的背景颜色
   
UIView *selectedView = [[UIView
alloc] initWithFrame:cell.contentView.frame];
    selectedView.backgroundColor = [UIColor
orangeColor];
    cell.selectedBackgroundView = selectedView;

//----------------自定义导航栏

    //-----1创建一个导航栏

    UINavigationBar *a = [[UINavigationBar
alloc]initWithFrame:CGRectMake(0,
300,
320, 44)];

    a.barTintColor = [UIColor
redColor];//设置背景颜色

    a.tintColor = [UIColor
blackColor];//字体颜色

    a.translucent =
NO;//不透明度

    //-----2创建一个导航栏集合

    UINavigationItem * b = [[UINavigationItem
alloc]
initWithTitle:nil];

    //-----3创建按钮
   
UIBarButtonItem * left = [[UIBarButtonItem
alloc] initWithTitle:@"回左边" style:UIBarButtonItemStyleBordered
target:self action:@selector(left:)];
   
UIBarButtonItem * right = [[UIBarButtonItem
alloc] initWithTitle:@"去右边" style:UIBarButtonItemStyleBordered
target:self action:@selector(right:)];

    //-----4添加导航标题
    b.title =
@"June";

    //-----5把集合加到导航栏中

    [a pushNavigationItem:b
animated:NO];

    //-----6把按钮添加到导航栏左右

    b.LeftBarButtonItem = left;

    b.rightBarButtonItem = right;

    //-----7添加
释放
    [self.view
addSubview:a];
    [a
release];
    [b
release];
    [left
release];
[right
release];

//----------------池
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath
*)indexPath
{
   
static NSString * cellIdentify =
@"3";//创建一个静态变量

    //------------------------------------------------------自定义方法

    //从池子中取出

    //调用自定义tableview
   
MainTableViewCell * cell= [tableView
dequeueReusableCellWithIdentifier:cellIdentify];//teble要从名字叫cell的池子中取出不用的cell
   
if (!cell) {//如果b为空

         //调用自定义tableview

        cell = [[[MainTableViewCell
alloc] initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:@"hello"]autorelease];
    }
   
Student * stu = [_tableArray
objectAtIndex:indexPath.row];//多少行
    cell.labelName.text = stu.name;
    cell.labelPhoto.image = [UIImage
imageNamed:stu.photo];

    //------------------------------------------------------自定义方法

    

////------------------------------------------------------系统方法
   
NSString * str = [NSString
stringWithFormat:@"%d_%d",indexPath.section,indexPath.row];//创建字符串把内容添加到标题框中
       
NSDictionary * name = [_tableArray
objectAtIndex:indexPath.row];//按下标取出数组的内容保存到字典中
   
NSString * name = [_tableArray objectAtIndex:indexPath.row];//按下标取出数组的内容保存到字符串中

    UITableViewCell * a = [[[UITableViewCell
alloc] initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:@"hello"]
autorelease];//设置风格

    cell.imageView.image = [UIImage
imageNamed:@"1.png"];//添加图片
    cell.detailTextLabel.text = [name
objectForKey:@"sex"];//设置标题文本
    cell.textLabel.text = [name
objectForKey:@"name"];//设置文本

////------------------------------------------------------系统方法
   
return cell ;
}

//----------------设置cell行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
   
return 1;
}

//----------------设置cell的高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath
*)indexPath
{
   
if (indexPath.section ==
0) {//如果是第一行
高度为50
       
return 50;
    }
else {
       
return 80;
    }
}

//----------------设置section数
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
   
return 1;
}

//----------------设置上section的title
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
   
return @"啊";
}

//----------------设置下section的title
- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section{
   
return @"啊";
}

//----------------用以定制自定义的section头部视图-Header
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{

    return
nil;
}

//----------------用以定制自定义的section底部视图-Footer
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
   
UIImageView *imageView_=[[UIImageView
alloc]initWithFrame:CGRectMake(0,
0, 320,
20)];
    imageView_.image=[UIImage
imageNamed:@"1000.png"];
   
return imageView_;
}

//----------------设置上section的高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
   
return 50;
}

//----------------设置下section的高度
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
   
return 30;
}

//----------------行缩进
-(NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath
*)indexPath{
   
NSUInteger row = [indexPath
row];
   
return row;
}

//----------------移动row时执行
-(NSIndexPath *)tableView:(UITableView *)tableView targetIndexPathForMoveFromRowAtIndexPath:(NSIndexPath
*)sourceIndexPath toProposedIndexPath:(NSIndexPath *)proposedDestinationIndexPath
{

    NSLog(@"targetIndexPathForMoveFromRowAtIndexPath");

   
//用于限制只在当前section下面才可以移动
   
if(sourceIndexPath.section != proposedDestinationIndexPath.section){
       
return sourceIndexPath;
    }
   
return proposedDestinationIndexPath;
}

//----------------section的点击事件(//点击Cell响应事件 )
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
*)indexPath//找到标题栏的点击事件(//选中Cell响应事件
)
{

    NSMutableDictionary *dic = [_tableArray
objectAtIndex:indexPath.section];//获取数组中当前点击的下标(因为之前储存数据是字典类,所以要用字典接收)
   
NSMutableArray *someStu = [dic
objectForKey:@"array"];//找到字典中key是array的内容
   
Student * tum = [someStu
objectAtIndex:indexPath.row];//对应的行的下标给数据类对象

[tableView
deselectRowAtIndexPath:indexPath animated:YES];//选中后的反显颜色即刻消失

   
//当点击对应行的时候

    JuneViewController * view = [[JuneViewController
alloc]
init];

    view.contacts = tum;//把定义好数据类的对象传给需要的视图(把整个对象传过去,包含了所有内容)

    [self.navigationController
pushViewController:view animated:NO];
    [view
release];

   
//把里面的内容取出来给联系人类相对应的属性
}

//----------------在需要传值的页面声明 传过来的是哪个储存数据的类

@class
Student;
@interface NewViewController :
UIViewController

@property (nonatomic ,retain)
Student *myStu;

@end//然后可以直接调用数据类中的内容

//----------------移动cell (是否可以移动cell
默认NO)
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath
*)indexPath
{

    return
YES;
}

//----------------移动时的动作
-(void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath
*)sourceIndexPath toIndexPath:(NSIndexPath*)destinationIndexPath
{

   
//开始位置和当前位置交换

//    [_tableArray exchangeObjectAtIndex:sourceIndexPath.row withObjectAtIndex:destinationIndexPath.row];

    //先删除后添加
   
Sutdent * stu = [[_tableArray
objectAtIndex:sourceIndexPath.row]
retain];
    [_tableArray
removeObjectAtIndex:sourceIndexPath.row];//先在数组中删除原始位置
    [_tableArray
insertObject:stu atIndex:destinationIndexPath.row];//添加当前位置(移动到的那个新位置)
    [stu
release];

    
}

//----------------滑动可以编辑时执行
-(void)tableView:(UITableView *)tableView willBeginEditingRowAtIndexPath:(NSIndexPath
*)indexPath
{

    NSLog(@"willBeginEditingRowAtIndexPath");
}

//----------------将取消选中时执行,
也就是上次先中的行
-(NSIndexPath *)tableView:(UITableView *)tableView willDeselectRowAtIndexPath:(NSIndexPath
*)indexPath
{

    NSLog(@"上次选中的行是  \n indexpath=%@",indexPath);
   
return indexPath;
}

//----------------当前点击时提交的方法//风格
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath
{
   
NSLog(@"%d",indexPath.row);

    if (editingStyle ==
UITableViewCellEditingStyleInsert) {//如果他是加号

        //创建一个新的cell

        Sutdent * stu = [Sutdent
studentWithImage:@"a"
title:@"a"
phone:@"a"
sex:@"a"];
        [_tableArray
addObject:stu];

        //因为之前cell是固定的,所以要

        [_tableView
reloadData];//重新执行一遍所有的协议所执行的方法(刷新界面)
    } 

    if (editingStyle ==
UITableViewCellEditingStyleDelete)
    {
        [_tableArray
removeObjectAtIndex:indexPath.row];
        [_tableView
reloadData];
    }
}

//----------------编辑按钮的点击事件 (navigationController按钮点击事件)
- (void)editAction:(id)sender

{  
//在点击时首先让它处于
编辑状态
   
self.editing =
YES;
   
//判断
   
if (_tableView.editing) {

        [_tableView
setEditing:NO
animated:YES];//在编辑时
    }
else
    {

        [_tableView
setEditing:YES
animated:YES];//在编辑时
    }
}

//----------------编辑状态时候的样式 (navigationController按钮点击事件)
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath
*)indexPath
{
   
if (indexPath.row ==
0) {//只让第一行改变编辑样式

        return
UITableViewCellEditingStyleInsert;
    }

//    return UITableViewCellEditingStyleDelete | UITableViewCellEditingStyleInsert;

    return
UITableViewCellEditingStyleDelete;//删除格式
}

//----------------哪行能被编辑 (navigationController按钮点击事件)//划动cell是否出现del按钮
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath
*)indexPath
{

//    if (indexPath.row == 0) {//设定只能编辑第一行

//        return YES;

//    }

//    return NO;

    return
YES;
}

//----------------重写系统的编辑方法
- (void)setEditing:(BOOL)editing
{

   
//要想编辑本类内容必须经过上一级同意

    super.editing =
YES;//让父类处于编辑状态
}

//----------------添加索引标题
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{

    NSMutableArray * array = [[[NSMutableArray
alloc]init]
autorelease];

    //    [array addObject:UITableViewIndexSearch];//添加索引标题放大镜

//    for (char c = 'A';  c <='Z'; c++) {

//        [array addObject:[NSString stringWithFormat:@"%c",c]];

//    }
   
for (NSDictionary * a 
in _tableArray) {
        [array
addObject:[a objectForKey:@"name"]];
    }
   
return array;
}

//----------------cell右边按钮格式为UITableViewCellAccessoryDetailDisclosureButton时,点击按扭时调用的方法
-(void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath
*)indexPath{

    NSLog(@"当前点击的详情button \n indexpath=%@",indexPath);
}

UIScrollView

//----------------------------------------------------------------------------------------------------

//----------创建滚动视图
   
UIScrollView *scroll = [[UIScrollView
alloc] initWithFrame:CGRectMake(0,
100, 320,
200)];
    [self.view
addSubview:scroll];
    [scroll
release];
   
UILabel *content = [[UILabel
alloc] initWithFrame:CGRectMake(0,
0, 320,
0)];
    [content
setText:self.bookModel.content];

    [content setBackgroundColor:[UIColor
redColor]];
    [content
setNumberOfLines:0];
    [scroll
addSubview:content];
    [content
release];

//-----------让文本与lable匹配
   
//麻烦

//    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:17],NSFontAttributeName, nil];

//    CGRect rect = [self.bookModel.content boundingRectWithSize:CGSizeMake(320, 10000) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];

//    [content setFrame:CGRectMake(0, 0, 320, rect.size.height)];
   
//简单
    [content
sizeToFit];
    [scroll
setContentSize:CGSizeMake(320, content.frame.size.height)];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息